Skip to content

Commit 956f466

Browse files
committed
use yarn pack
1 parent 4c85ad4 commit 956f466

File tree

6 files changed

+74
-199
lines changed

6 files changed

+74
-199
lines changed

Diff for: lib/.npmignore

-5
This file was deleted.

Diff for: lib_dev/paths.js

+9
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ export const compilerVersionFile = path.resolve(
8383
"bs_version.ml",
8484
);
8585

86+
/**
87+
* path: `<projectDir>/packages/artifacts.txt`
88+
*/
89+
export const artifactListFile = path.resolve(
90+
projectDir,
91+
"packages",
92+
"artifacts.txt",
93+
);
94+
8695
/**
8796
* path: `<projectDir>/_build/install/default/bin/`
8897
*/

Diff for: package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@
5656
},
5757
"files": [
5858
"CHANGELOG.md",
59+
"COPYING",
60+
"COPYING.LESSER",
5961
"CREDITS.md",
6062
"ninja.COPYING",
6163
"docs/docson/build-schema.json",
62-
"lib/js/*.js",
63-
"lib/es6/*.js",
64+
"lib",
6465
"cli"
6566
],
6667
"exports": {

Diff for: packages/artifacts.txt

+1-36
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,6 @@ cli/rescript.js
1313
cli/rescript/dump.js
1414
cli/rescript/format.js
1515
cli/rewatch.js
16-
darwin/bsb_helper.exe
17-
darwin/bsc.exe
18-
darwin/ninja.exe
19-
darwin/rescript-editor-analysis.exe
20-
darwin/rescript-tools.exe
21-
darwin/rescript.exe
22-
darwin/rewatch.exe
23-
darwinarm64/bsb_helper.exe
24-
darwinarm64/bsc.exe
25-
darwinarm64/ninja.exe
26-
darwinarm64/rescript-editor-analysis.exe
27-
darwinarm64/rescript-tools.exe
28-
darwinarm64/rescript.exe
29-
darwinarm64/rewatch.exe
3016
docs/docson/build-schema.json
3117
lib/bstracing
3218
lib/es6/Belt.js
@@ -1227,26 +1213,5 @@ lib/ocaml/Stdlib_WeakSet.cmi
12271213
lib/ocaml/Stdlib_WeakSet.cmj
12281214
lib/ocaml/Stdlib_WeakSet.cmt
12291215
lib/ocaml/Stdlib_WeakSet.res
1230-
linux/bsb_helper.exe
1231-
linux/bsc.exe
1232-
linux/ninja.exe
1233-
linux/rescript-editor-analysis.exe
1234-
linux/rescript-tools.exe
1235-
linux/rescript.exe
1236-
linux/rewatch.exe
1237-
linuxarm64/bsb_helper.exe
1238-
linuxarm64/bsc.exe
1239-
linuxarm64/ninja.exe
1240-
linuxarm64/rescript-editor-analysis.exe
1241-
linuxarm64/rescript-tools.exe
1242-
linuxarm64/rescript.exe
1243-
linuxarm64/rewatch.exe
1244-
ninja.COPYING
1216+
ninja/COPYING
12451217
package.json
1246-
win32/bsb_helper.exe
1247-
win32/bsc.exe
1248-
win32/ninja.exe
1249-
win32/rescript-editor-analysis.exe
1250-
win32/rescript-tools.exe
1251-
win32/rescript.exe
1252-
win32/rewatch.exe

Diff for: scripts/npmPack.js

+61-70
Original file line numberDiff line numberDiff line change
@@ -2,89 +2,80 @@
22

33
// @ts-check
44

5-
// NOTE:
6-
// We cannot use `yarn pack` since we need to set our OCaml binaries executable.
7-
// Yarn (Berry) only allow `bin` to be executable, wouldn't preserve permission bits.
8-
9-
// This performs `npm pack` and retrieves the list of artifact files from the output.
5+
// This performs `yarn pack` and retrieves the list of artifact files from the output.
106
//
11-
// In local dev, invoke it with `-updateArtifactList` to perform a dry run of `npm pack`
7+
// In local dev, invoke it with `-updateArtifactList` to perform a dry run of `yarn pack`
128
// and recreate `packages/artifacts.txt`.
13-
// The exes for all platforms will then be included in the list, even if not present locally.
149
//
15-
// In CI, the scripts is invoked without options. It then performs `npm pack` for real,
10+
// In CI, the scripts is invoked without options. It then performs `yarn pack` for real,
1611
// recreates the artifact list and verifies that it has no changes compared to the committed state.
1712

18-
/**
19-
* @typedef {{
20-
* path: string,
21-
* size: number,
22-
* mode: number,
23-
* }} PackOutputFile
24-
*
25-
* @typedef {{
26-
* files: PackOutputFile[],
27-
* entryCount: number,
28-
* bundled: unknown[],
29-
* }} PackOutputEntry
30-
*
31-
* @typedef {[PackOutputEntry]} PackOutput
13+
import { spawn, execSync } from "node:child_process";
14+
import fs from "node:fs";
15+
import { parseArgs } from "node:util";
16+
import { artifactListFile } from "#dev/paths";
17+
18+
/**
19+
* @typedef {(
20+
* | { "base": string }
21+
* | { "location": string }
22+
* | { "output": string }
23+
* )} YarnPackOutputLine
3224
*/
3325

34-
import { execSync, spawnSync } from "node:child_process";
35-
import fs from "node:fs";
36-
import path from "node:path";
37-
import { projectDir } from "#dev/paths";
26+
const { values } = parseArgs({
27+
args: process.argv.slice(2),
28+
options: {
29+
updateArtifactList: {
30+
type: "boolean",
31+
short: "u",
32+
},
33+
},
34+
});
3835

39-
const mode = process.argv.includes("-updateArtifactList")
36+
const mode = values.updateArtifactList
4037
? "updateArtifactList"
4138
: "package";
4239

43-
const fileListPath = path.join(projectDir, "packages", "artifacts.txt");
44-
45-
const output = spawnSync(
46-
`npm pack --json${mode === "updateArtifactList" ? " --dry-run" : ""}`,
47-
{
48-
cwd: projectDir,
49-
encoding: "utf8",
50-
shell: true,
51-
},
52-
).stdout;
53-
54-
/** @type {PackOutput} */
55-
const parsedOutput = JSON.parse(output);
56-
let filePaths = parsedOutput[0].files.map(file => file.path);
57-
58-
if (mode === "updateArtifactList") {
59-
filePaths = Array.from(new Set(filePaths.concat(getFilesAddedByCI())));
40+
const child = spawn(
41+
"yarn",
42+
[
43+
"workspace",
44+
"rescript",
45+
"pack",
46+
"--json",
47+
mode === "updateArtifactList" ? "--dry-run" : "",
48+
].filter(Boolean),
49+
);
50+
const exitCode = new Promise((resolve, reject) => {
51+
child.once("error", reject);
52+
child.once("close", code => resolve(code));
53+
});
54+
55+
fs.unlinkSync(artifactListFile);
56+
57+
for await (const chunk of child.stdout.setEncoding("utf8")) {
58+
const lines = /** @type {string} */ (chunk).trim().split(/\s/);
59+
for (const line of lines) {
60+
/** @type {YarnPackOutputLine} */
61+
const json = JSON.parse(line);
62+
if ("location" in json) {
63+
// Workaround for false positive reports
64+
// See https://github.com/yarnpkg/berry/issues/6766
65+
if (json.location.startsWith("_build")) {
66+
continue;
67+
}
68+
fs.appendFileSync(
69+
artifactListFile,
70+
json.location + "\n",
71+
"utf8",
72+
);
73+
}
74+
}
6075
}
6176

62-
filePaths.sort();
63-
fs.writeFileSync(fileListPath, filePaths.join("\n"));
77+
await exitCode;
6478

6579
if (mode === "package") {
66-
execSync(`git diff --exit-code ${fileListPath}`, { stdio: "inherit" });
67-
}
68-
69-
function getFilesAddedByCI() {
70-
const platforms = ["darwin", "darwinarm64", "linux", "linuxarm64", "win32"];
71-
const exes = [
72-
"bsb_helper.exe",
73-
"bsc.exe",
74-
"ninja.exe",
75-
"rescript.exe",
76-
"rescript-editor-analysis.exe",
77-
"rescript-tools.exe",
78-
"rewatch.exe",
79-
];
80-
81-
const files = ["ninja.COPYING"];
82-
83-
for (const platform of platforms) {
84-
for (const exe of exes) {
85-
files.push(`${platform}/${exe}`);
86-
}
87-
}
88-
89-
return files;
80+
execSync(`git diff --exit-code ${artifactListFile}`, { stdio: "inherit" });
9081
}

Diff for: tools/CHANGELOG.md

-86
This file was deleted.

0 commit comments

Comments
 (0)