Skip to content

Commit 10166c4

Browse files
trusted publishing only 2
1 parent 71c7797 commit 10166c4

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

scripts/publish-npm.mjs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { execSync } from "node:child_process";
2-
import { mkdtempSync, readFileSync, writeFileSync } from "node:fs";
2+
import {
3+
cpSync,
4+
mkdtempSync,
5+
readFileSync,
6+
rmSync,
7+
writeFileSync,
8+
} from "node:fs";
39
import { tmpdir } from "node:os";
410
import { join } from "node:path";
511
import { resolve } from "node:path";
@@ -150,21 +156,17 @@ const publishPackage = ({ path, name }, shouldPublish) => {
150156
console.log(
151157
`npm_config_workspace=${process.env.npm_config_workspace || ""} npm_config_workspaces=${process.env.npm_config_workspaces || ""}`
152158
);
159+
const publishRoot = mkdtempSync(join(tmpdir(), "rescript-mui-publish-"));
160+
const tempPkgPath = join(publishRoot, path);
161+
cpSync(path, tempPkgPath, { recursive: true });
162+
rmSync(join(tempPkgPath, "node_modules"), { recursive: true, force: true });
153163
pkgJson.version = targetVersion;
154-
writePackageJson(path, pkgJson);
155-
try {
156-
const tgzName = run("npm pack --quiet", { cwd: path, env: npmEnv });
157-
const tgzPath = resolve(join(path, tgzName));
158-
console.log(`Packed tarball: ${tgzPath}`);
159-
const publishCwd = mkdtempSync(join(tmpdir(), "rescript-mui-publish-"));
160-
execSync(`npm publish ${tgzPath} --access public --tag ${distTag} --provenance`, {
161-
cwd: publishCwd,
162-
stdio: "inherit",
163-
env: npmEnv,
164-
});
165-
} finally {
166-
execSync(`git checkout -- package.json`, { cwd: path });
167-
}
164+
writePackageJson(tempPkgPath, pkgJson);
165+
execSync(`npm publish --access public --tag ${distTag} --provenance`, {
166+
cwd: tempPkgPath,
167+
stdio: "inherit",
168+
env: npmEnv,
169+
});
168170
};
169171

170172
const changedPaths = getChangedPaths();

0 commit comments

Comments
 (0)