Skip to content

Commit 949139c

Browse files
committed
Include the contents of @rescript/runtime in the artifact list
1 parent 6c0fd56 commit 949139c

File tree

8 files changed

+101
-103
lines changed

8 files changed

+101
-103
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,9 @@ jobs:
478478
shell: bash
479479

480480
- name: Check artifact list
481-
run: node ./scripts/npmPack.js
481+
run: |
482+
node ./scripts/updateArtifactList.js
483+
git diff --exit-code packages/artifacts.json
482484
483485
- name: Publish packages to pkg.pr.new
484486
run: |

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ make artifacts
111111
- OCaml Code: snake case format is used, e.g, `to_string`
112112
- ReScript Code: the camel case format is used, e.g `toString`
113113

114-
## Adding new Files to the Npm Package
114+
## Adding new Files to the Npm Packages
115115

116-
To make sure that no files are added to or removed from the npm package inadvertently, an artifact list is kept at `packages/artifacts.txt`. During CI build, it is verified that only the files that are listed there are actually included in the npm package.
116+
To make sure that no files are added to or removed from the `rescript` or `@rescript/runtime` npm package inadvertently, an artifact list is kept at `packages/artifacts.json`. During CI build, it is verified that only the files that are listed there are actually included in the npm packages.
117117

118-
After adding a new file to the repository that should go into the npm package - e.g., a new stdlib module -, run `make artifacts`.
118+
After adding a new file to the repository that should go into one of the npm packages - e.g., a new stdlib module -, run `make artifacts`.
119119

120120
## Test the compiler
121121

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ lib:
5555
yarn workspace @rescript/runtime build
5656

5757
artifacts: lib
58-
./scripts/npmPack.js --updateArtifactList
58+
./scripts/updateArtifactList.js
5959

6060
# Builds the core playground bundle (without the relevant cmijs files for the runtime)
6161
playground:

lib_dev/paths.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ export const compilerVersionFile = path.resolve(
6767
);
6868

6969
/**
70-
* path: `<projectDir>/packages/artifacts.txt`
70+
* path: `<projectDir>/packages/artifacts.json`
7171
*/
7272
export const artifactListFile = path.resolve(
7373
projectDir,
7474
"packages",
75-
"artifacts.txt",
75+
"artifacts.json",
7676
);
7777

7878
/**

packages/artifacts.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"rescript": [
3+
"CHANGELOG.md",
4+
"COPYING",
5+
"COPYING.LESSER",
6+
"CREDITS.md",
7+
"LICENSE",
8+
"README.md",
9+
"cli/bsc.js",
10+
"cli/bstracing.js",
11+
"cli/common/args.js",
12+
"cli/common/bins.js",
13+
"cli/common/bsb.js",
14+
"cli/common/minisocket.js",
15+
"cli/rescript-legacy.js",
16+
"cli/rescript-legacy/dump.js",
17+
"cli/rescript-legacy/format.js",
18+
"cli/rescript-tools.js",
19+
"cli/rescript.js",
20+
"docs/docson/build-schema.json",
21+
"ninja/COPYING",
22+
"package.json"
23+
],
24+
"@rescript/runtime": [
25+
"package.json"
26+
]
27+
}

packages/artifacts.txt

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

scripts/npmPack.js

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

scripts/updateArtifactList.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env node
2+
3+
// @ts-check
4+
5+
import { spawn } from "node:child_process";
6+
import * as fs from "node:fs/promises";
7+
import * as readline from "node:readline/promises";
8+
import { artifactListFile } from "#dev/paths";
9+
10+
/**
11+
* @typedef {(
12+
* | { "base": string }
13+
* | { "location": string }
14+
* | { "output": string }
15+
* )} YarnPackOutputLine
16+
*/
17+
18+
/**
19+
* @param {string} pkg
20+
*/
21+
async function getArtifacts(pkg) {
22+
const args = ["workspace", pkg, "pack", "--json", "--dry-run"];
23+
24+
const files = [];
25+
26+
const child = spawn("yarn", args);
27+
28+
const exitCode = new Promise((resolve, reject) => {
29+
child.once("error", reject);
30+
child.once("close", code => resolve(code));
31+
});
32+
33+
for await (const line of readline.createInterface({
34+
input: child.stdout.setEncoding("utf8"),
35+
crlfDelay: Number.POSITIVE_INFINITY,
36+
})) {
37+
/** @type {YarnPackOutputLine} */
38+
const json = JSON.parse(line);
39+
if ("location" in json) {
40+
// Workaround for false positive reports
41+
// See https://github.com/yarnpkg/berry/issues/6766
42+
if (json.location.startsWith("_build")) {
43+
continue;
44+
}
45+
46+
files.push(json.location);
47+
}
48+
}
49+
50+
await exitCode;
51+
52+
return files;
53+
}
54+
55+
/** @type {Record<string, string[]>} */
56+
const artifactsPerPackage = {};
57+
58+
for (const pkg of ["rescript", "@rescript/runtime"]) {
59+
artifactsPerPackage[pkg] = await getArtifacts(pkg);
60+
}
61+
62+
await fs.writeFile(
63+
artifactListFile,
64+
JSON.stringify(artifactsPerPackage, null, 2),
65+
);

0 commit comments

Comments
 (0)