Skip to content

Commit ed8ba44

Browse files
committed
use yarn pack to handle workspace protocol
1 parent 54053f3 commit ed8ba44

File tree

8 files changed

+76
-136
lines changed

8 files changed

+76
-136
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -463,14 +463,14 @@ jobs:
463463
- name: Move artifacts
464464
run: ./scripts/moveArtifacts.sh
465465

466-
- name: npm pack (rescript) + check artifact list
466+
- name: yarn pack (rescript) + check artifact list
467467
run: node ./scripts/npmPack.js
468468

469469
- name: Copy JS files to stdlib package
470470
run: mkdir -p packages/std/lib && cp -R lib/es6 lib/js packages/std/lib
471471

472-
- name: npm pack (@rescript/std)
473-
run: npm pack
472+
- name: yarn pack (@rescript/std)
473+
run: yarn pack
474474
working-directory: packages/std
475475

476476
- name: Prepare package upload
@@ -557,8 +557,8 @@ jobs:
557557
env:
558558
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
559559
run: |
560-
npm publish rescript-${{ needs.package.outputs.rescript_version }}.tgz --tag ci
561-
npm publish rescript-std-${{ needs.package.outputs.rescript_version }}.tgz --tag ci
560+
yarn npm publish rescript-${{ needs.package.outputs.rescript_version }}.tgz --tag ci
561+
yarn npm publish rescript-std-${{ needs.package.outputs.rescript_version }}.tgz --tag ci
562562
563563
- name: Update Website Playground
564564
env:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,5 @@ tests/analysis_tests/**/*.bs.js
9090
!.yarn/versions
9191

9292
*.tsbuildinfo
93+
94+
*.tgz

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@
5555
"typecheck": "tsc"
5656
},
5757
"files": [
58+
"COPYING",
59+
"COPYING.LESSER",
5860
"CHANGELOG.md",
5961
"CREDITS.md",
60-
"ninja.COPYING",
6162
"darwin",
6263
"darwinarm64",
6364
"linux",
@@ -87,6 +88,7 @@
8788
"typescript": "5.8.2"
8889
},
8990
"workspaces": [
91+
"tools",
9092
"packages/*",
9193
"tests/dependencies/**",
9294
"tests/analysis_tests/**",

packages/artifacts.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,11 +1242,12 @@ linuxarm64/rescript-tools.exe
12421242
linuxarm64/rescript.exe
12431243
linuxarm64/rewatch.exe
12441244
ninja.COPYING
1245+
ninja/COPYING
12451246
package.json
12461247
win32/bsb_helper.exe
12471248
win32/bsc.exe
12481249
win32/ninja.exe
12491250
win32/rescript-editor-analysis.exe
12501251
win32/rescript-tools.exe
12511252
win32/rescript.exe
1252-
win32/rewatch.exe
1253+
win32/rewatch.exe

scripts/moveArtifacts.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ mv binaries-linuxarm64/* rewatch-linuxarm64/* linuxarm64
3535
mv binaries-win32/* rewatch-win32/* win32
3636

3737
mv lib-ocaml lib/ocaml
38-
mv ninja/COPYING ninja.COPYING
3938

4039
check_statically_linked "linux"
4140
check_statically_linked "linuxarm64"

scripts/npmPack.js

Lines changed: 63 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,70 +2,96 @@
22

33
// @ts-check
44

5-
// TODO: Use `yarn pack --json` instead.
6-
7-
// This performs `npm pack` and retrieves the list of artifact files from the output.
5+
// This performs `yarn pack --json` and retrieves the list of artifact files from the output.
86
//
97
// In local dev, invoke it with `-updateArtifactList` to perform a dry run of `npm pack`
10-
// and recreate `packages/artifacts.txt`.
8+
// and recreate `packages/artifacts.jsonl`.
119
// The exes for all platforms will then be included in the list, even if not present locally.
1210
//
13-
// In CI, the scripts is invoked without options. It then performs `npm pack` for real,
11+
// In CI, the scripts is invoked without options. It then performs `yarn pack` for real,
1412
// recreates the artifact list and verifies that it has no changes compared to the committed state.
1513

16-
/**
17-
* @typedef {{
18-
* path: string,
19-
* size: number,
20-
* mode: number,
21-
* }} PackOutputFile
22-
*
23-
* @typedef {{
24-
* files: PackOutputFile[],
25-
* entryCount: number,
26-
* bundled: unknown[],
27-
* }} PackOutputEntry
28-
*
29-
* @typedef {[PackOutputEntry]} PackOutput
30-
*/
31-
32-
import { execSync, spawnSync } from "node:child_process";
14+
import { execSync, spawn } from "node:child_process";
3315
import fs from "node:fs";
3416
import path from "node:path";
3517
import { projectDir } from "#dev/paths";
3618

19+
/**
20+
* @typedef {{ base: string }} YarnPackBase
21+
* @typedef {{ location: string }} YarnPackEntry
22+
* @typedef {{ output: string }} YarnPackResult
23+
*
24+
* @typedef {(
25+
* | YarnPackBase
26+
* | YarnPackEntry
27+
* | YarnPackResult
28+
* )} YarnPackOutput
29+
*/
30+
3731
const mode = process.argv.includes("-updateArtifactList")
3832
? "updateArtifactList"
3933
: "package";
4034

4135
const fileListPath = path.join(projectDir, "packages", "artifacts.txt");
4236

43-
const output = spawnSync(
44-
`npm pack --json${mode === "updateArtifactList" ? " --dry-run" : ""}`,
37+
/** @type {Set<string>} */
38+
const fileList = new Set();
39+
40+
const child = spawn(
41+
"yarn",
42+
[
43+
"pack",
44+
"--json",
45+
mode === "updateArtifactList" ? "--dry-run" : "",
46+
].filter(Boolean),
4547
{
4648
cwd: projectDir,
47-
encoding: "utf8",
48-
shell: true,
49+
shell: process.platform === "win32",
50+
stdio: ["inherit", "pipe", "pipe"],
4951
},
50-
).stdout;
52+
);
53+
54+
const exitCode = new Promise((res, rej) => {
55+
child.once("close", code => res(code));
56+
child.once("error", rej);
57+
});
58+
59+
for await (const chunk of child.stdout.setEncoding("utf8")) {
60+
const lines = /** @type {string} */ (chunk).trim().split(/\s/);
61+
for (const line of lines) {
62+
/** @type {YarnPackOutput} */
63+
const json = JSON.parse(line);
64+
if ("location" in json) {
65+
fileList.add(json.location);
66+
}
67+
}
68+
}
5169

52-
/** @type {PackOutput} */
53-
const parsedOutput = JSON.parse(output);
54-
let filePaths = parsedOutput[0].files.map(file => file.path);
70+
await exitCode;
5571

56-
if (mode === "updateArtifactList") {
57-
filePaths = Array.from(new Set(filePaths.concat(getFilesAddedByCI())));
72+
for await (const file of getFilesAddedByCI()) {
73+
fileList.add(file);
5874
}
5975

60-
filePaths.sort();
61-
fs.writeFileSync(fileListPath, filePaths.join("\n"));
76+
fs.unlinkSync(fileListPath);
77+
for (const file of [...fileList].toSorted()) {
78+
fs.appendFileSync(fileListPath, file + "\n");
79+
}
6280

6381
if (mode === "package") {
6482
execSync(`git diff --exit-code ${fileListPath}`, { stdio: "inherit" });
6583
}
6684

67-
function getFilesAddedByCI() {
68-
const platforms = ["darwin", "darwinarm64", "linux", "linuxarm64", "win32"];
85+
function *getFilesAddedByCI() {
86+
yield "ninja.COPYING";
87+
88+
const platforms = [
89+
"darwin",
90+
"darwinarm64",
91+
"linux",
92+
"linuxarm64",
93+
"win32",
94+
];
6995
const exes = [
7096
"bsb_helper.exe",
7197
"bsc.exe",
@@ -76,13 +102,9 @@ function getFilesAddedByCI() {
76102
"rewatch.exe",
77103
];
78104

79-
const files = ["ninja.COPYING"];
80-
81105
for (const platform of platforms) {
82106
for (const exe of exes) {
83-
files.push(`${platform}/${exe}`);
107+
yield `${platform}/${exe}`;
84108
}
85109
}
86-
87-
return files;
88110
}

tools/CHANGELOG.md

Lines changed: 0 additions & 86 deletions
This file was deleted.

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "ES2022",
3+
"target": "ESNext",
44
"module": "NodeNext",
55
"moduleResolution": "NodeNext",
66
"allowJs": true,

0 commit comments

Comments
 (0)