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/makeArtifactList.js deleted file mode 100755 index 477202b8f2..0000000000 --- a/scripts/makeArtifactList.js +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env node - -// This script creates the list of the files that go into the rescript npm package. -// -// 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 CI, it is invoked with -check. It then recreates the list and verifies -// that it has no changes compared to the committed state. - -const { spawnSync, execSync } = require("child_process"); -const path = require("path"); -const fs = require("fs"); - -const isCheckMode = process.argv.includes("-check"); - -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 [{ files }] = JSON.parse(output); -let filePaths = files.map(file => file.path); - -if (!isCheckMode) { - filePaths = Array.from(new Set(filePaths.concat(getFilesAddedByCI()))); -} - -filePaths.sort(); -fs.writeFileSync(fileListPath, filePaths.join("\n")); - -if (isCheckMode) { - execSync(`git diff --exit-code ${fileListPath}`, { stdio: "inherit" }); -} - -function getFilesAddedByCI() { - const platforms = ["darwin", "darwinarm64", "linux", "linuxarm64", "win32"]; - const exes = [ - "bsb_helper.exe", - "bsc.exe", - "ninja.exe", - "rescript.exe", - "rewatch.exe", - ]; - - const files = ["ninja.COPYING"]; - - for (let platform of platforms) { - for (let exe of exes) { - files.push(`${platform}/${exe}`); - } - } - - return files; -} diff --git a/scripts/npmPack.js b/scripts/npmPack.js new file mode 100755 index 0000000000..a4eae27d39 --- /dev/null +++ b/scripts/npmPack.js @@ -0,0 +1,83 @@ +#!/usr/bin/env node +// @ts-check + +// This performs `npm pack` and retrieves the list of artifact files from the output. +// +// 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, 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 {{ + * 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"); + +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 --json" + (mode === "updateArtifactList" ? " --dry-run" : ""), + { + cwd: rootPath, + encoding: "utf8", + shell: true, + }, +).stdout; + +/** @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()))); +} + +filePaths.sort(); +fs.writeFileSync(fileListPath, filePaths.join("\n")); + +if (mode === "package") { + execSync(`git diff --exit-code ${fileListPath}`, { stdio: "inherit" }); +} + +function getFilesAddedByCI() { + const platforms = ["darwin", "darwinarm64", "linux", "linuxarm64", "win32"]; + const exes = [ + "bsb_helper.exe", + "bsc.exe", + "ninja.exe", + "rescript.exe", + "rewatch.exe", + ]; + + const files = ["ninja.COPYING"]; + + for (let platform of platforms) { + for (let exe of exes) { + files.push(`${platform}/${exe}`); + } + } + + return files; +}