From ad9fdb7065b09c506d1dd8e64642157fa7267aec Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Mon, 29 Jul 2024 16:29:35 +0200 Subject: [PATCH 1/3] CI: don't run npm pack twice --- .github/workflows/ci.yml | 7 ++---- Makefile | 2 +- scripts/{makeArtifactList.js => npmPack.js} | 24 +++++++++++++-------- 3 files changed, 18 insertions(+), 15 deletions(-) rename scripts/{makeArtifactList.js => npmPack.js} (75%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bbadf5c8c1..2e6506df6b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -432,11 +432,8 @@ jobs: - name: Move artifacts run: ./scripts/moveArtifacts.sh - - name: Check artifact list - run: node ./scripts/makeArtifactList.js -check - - - name: npm pack (rescript) - run: npm pack + - name: npm pack (rescript) + check artifact list + run: node ./scripts/npmPack.js - name: Copy JS files to stdlib package run: mkdir -p packages/std/lib && cp -R lib/es6 lib/js packages/std/lib diff --git a/Makefile b/Makefile index 7d56445ffc..8dc45b0306 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,7 @@ lib: build node_modules/.bin/semver ./scripts/prebuilt.js artifacts: lib - ./scripts/makeArtifactList.js + ./scripts/npmPack.js -updateArtifactList # Builds the core playground bundle (without the relevant cmijs files for the runtime) playground: diff --git a/scripts/makeArtifactList.js b/scripts/npmPack.js similarity index 75% rename from scripts/makeArtifactList.js rename to scripts/npmPack.js index 477202b8f2..ded925b110 100755 --- a/scripts/makeArtifactList.js +++ b/scripts/npmPack.js @@ -1,4 +1,5 @@ #!/usr/bin/env node +// @ts-check // This script creates the list of the files that go into the rescript npm package. // @@ -13,28 +14,33 @@ const { spawnSync, execSync } = require("child_process"); const path = require("path"); const fs = require("fs"); -const isCheckMode = process.argv.includes("-check"); +const mode = process.argv.includes("-updateArtifactList") + ? "updateArtifactList" + : "package"; const rootPath = path.join(__dirname, ".."); const fileListPath = path.join(rootPath, "packages", "artifacts.txt"); -const output = spawnSync(`npm pack --dry-run --json`, { - cwd: rootPath, - encoding: "utf8", - shell: true, -}).stdout; +const output = spawnSync( + "npm pack --json" + (mode === "updateArtifactList" ? " --dry-run" : ""), + { + cwd: rootPath, + encoding: "utf8", + shell: true, + }, +).stdout; const [{ files }] = JSON.parse(output); -let filePaths = files.map(file => file.path); +let filePaths = files.map((/** @type {{ path: string; }} */ file) => file.path); -if (!isCheckMode) { +if (mode === "updateArtifactList") { filePaths = Array.from(new Set(filePaths.concat(getFilesAddedByCI()))); } filePaths.sort(); fs.writeFileSync(fileListPath, filePaths.join("\n")); -if (isCheckMode) { +if (mode === "package") { execSync(`git diff --exit-code ${fileListPath}`, { stdio: "inherit" }); } From 653fccf019edc69141efd9013e0e5a3715e4947b Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Tue, 30 Jul 2024 09:48:33 +0200 Subject: [PATCH 2/3] Add typedefs for PackOutput --- scripts/npmPack.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/scripts/npmPack.js b/scripts/npmPack.js index ded925b110..37590ec11a 100755 --- a/scripts/npmPack.js +++ b/scripts/npmPack.js @@ -10,6 +10,22 @@ // In CI, it is invoked with -check. It then recreates the list and verifies // that it has no changes compared to the committed state. +/** + * @typedef {{ + * path: string, + * size: number, + * mode: number, + * }} PackOutputFile + * + * @typedef {{ + * files: PackOutputFile[], + * entryCount: number, + * bundled: unknown[], + * }} PackOutputEntry + * + * @typedef {[PackOutputEntry]} PackOutput + */ + const { spawnSync, execSync } = require("child_process"); const path = require("path"); const fs = require("fs"); @@ -30,8 +46,9 @@ const output = spawnSync( }, ).stdout; -const [{ files }] = JSON.parse(output); -let filePaths = files.map((/** @type {{ path: string; }} */ file) => file.path); +/** @type {PackOutput} */ +const parsedOutput = JSON.parse(output); +let filePaths = parsedOutput[0].files.map(file => file.path); if (mode === "updateArtifactList") { filePaths = Array.from(new Set(filePaths.concat(getFilesAddedByCI()))); From 80b02d4034907e26319076879bc66656e7e1cd6e Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Tue, 30 Jul 2024 11:18:09 +0200 Subject: [PATCH 3/3] Update comments --- scripts/npmPack.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/npmPack.js b/scripts/npmPack.js index 37590ec11a..a4eae27d39 100755 --- a/scripts/npmPack.js +++ b/scripts/npmPack.js @@ -1,14 +1,14 @@ #!/usr/bin/env node // @ts-check -// This script creates the list of the files that go into the rescript npm package. +// This performs `npm pack` and retrieves the list of artifact files from the output. // -// In local dev, invoke it without any args after adding or removing files. -// It will then recreate the list and make sure that the exes for all platforms -// are in the list, even if not present locally. +// In local dev, invoke it with `-updateArtifactList` to perform a dry run of `npm pack` +// and recreate `packages/artifacts.txt`. +// The exes for all platforms will then be included in the list, even if not present locally. // -// In CI, it is invoked with -check. It then recreates the list and verifies -// that it has no changes compared to the committed state. +// In CI, the scripts is invoked without options. It then performs `npm pack` for real, +// recreates the artifact list and verifies that it has no changes compared to the committed state. /** * @typedef {{