From 0dcb249dbdccd9975e8ead90e3c9442a876c11f7 Mon Sep 17 00:00:00 2001 From: Roman Vyakhirev Date: Thu, 29 Oct 2026 14:03:47 +0100 Subject: [PATCH 1/8] chore(automation-utils): trim shell exports and pass cwd instead of pushd First step towards dropping shelljs. Export only the shelljs helpers that are used, and run git commands with execa's cwd option instead of pushd/popd. This also fixes two cases where the process directory was left changed: pushUpdateToTestProject returned early on "Nothing to commit" without popd, and zip() skipped popd when zipping failed. --- automation/utils/src/changelog.ts | 11 ++++----- automation/utils/src/shell.ts | 39 ++++--------------------------- automation/utils/src/steps.ts | 16 ++++++------- 3 files changed, 17 insertions(+), 49 deletions(-) diff --git a/automation/utils/src/changelog.ts b/automation/utils/src/changelog.ts index 88d698f8f0..8d2b3e3945 100644 --- a/automation/utils/src/changelog.ts +++ b/automation/utils/src/changelog.ts @@ -1,6 +1,6 @@ import { gh } from "./github.ts"; import type { PublishedInfo } from "./package-info.ts"; -import { exec, popd, pushd } from "./shell.ts"; +import { exec } from "./shell.ts"; export async function updateChangelogsAndCreatePR( info: PublishedInfo, @@ -20,11 +20,10 @@ export async function updateChangelogsAndCreatePR( console.log(`Committing changes and pushing '${branch}' to remote...`); const { stdout: root } = await exec(`git rev-parse --show-toplevel`, { stdio: "pipe" }); - pushd(root.trim()); - await exec(`git add '*/CHANGELOG.md'`); - await exec(`git commit -m "chore(${info.name}): update changelog"`); - await exec(`git push ${remoteName} ${branch}`); - popd(); + const cwd = root.trim(); + await exec(`git add '*/CHANGELOG.md'`, { cwd }); + await exec(`git commit -m "chore(${info.name}): update changelog"`, { cwd }); + await exec(`git push ${remoteName} ${branch}`, { cwd }); console.log(`Creating pull request for '${branch}'`); await gh.createGithubPRFrom({ diff --git a/automation/utils/src/shell.ts b/automation/utils/src/shell.ts index d447c54297..76975f2525 100644 --- a/automation/utils/src/shell.ts +++ b/automation/utils/src/shell.ts @@ -7,41 +7,11 @@ const { config } = shelljs; // Enable fast fail for all shelljs commands config.fatal = true; -// Export all except exec as we will execa to execute commands +// Only the file system helpers in use are exported; commands run through execa (see exec below). // KNOWN ISSUES: // - mv don't throw error https://github.com/shelljs/shelljs/issues/878 -export const { - cat, - cd, - chmod, - cp, - dirs, - echo, - env, - error, - exit, - find, - grep, - head, - ln, - ls, - mkdir, - mv, - popd, - pushd, - pwd, - rm, - sed, - set, - sort, - tail, - tempdir, - test, - touch, - uniq, - which -} = shelljs; -export { config as shelljsConfig }; +export const { chmod, cp, find, mkdir, mv, rm } = shelljs; +const { ls, popd, pushd } = shelljs; export function exec(command: string, options?: execa.Options): execa.ExecaChildProcess { const { stdio = "inherit", ...execaOptions } = options ?? {}; @@ -58,12 +28,13 @@ export function ensureFileExists(file: string): void { export async function zip(dir: string, fileName: string): Promise { return new Promise((resolve, reject) => { + // cross-zip has no cwd option, it zips relative to the process directory pushd("-q", dir); crossZip.zip(".", fileName, err => { + popd("-q"); if (err) { reject(err); } else { - popd("-q"); resolve(); } }); diff --git a/automation/utils/src/steps.ts b/automation/utils/src/steps.ts index 0b015f274b..d3b5dad673 100644 --- a/automation/utils/src/steps.ts +++ b/automation/utils/src/steps.ts @@ -13,7 +13,7 @@ import { copyMpkFiles, getMpkPaths } from "./monorepo.ts"; import { createModuleMpkInDocker } from "./mpk.ts"; import type { ModuleInfo, PackageInfo, WidgetInfo } from "./package-info.ts"; import { addFilesToPackageXml, type PackageType } from "./package-xml.ts"; -import { chmod, cp, ensureFileExists, exec, find, mkdir, popd, pushd, rm, unzip, zip } from "./shell.ts"; +import { chmod, cp, ensureFileExists, exec, mkdir, rm, unzip, zip } from "./shell.ts"; type Step = (params: { info: Info; config: Config }) => Promise; @@ -245,10 +245,9 @@ export async function pushUpdateToTestProject({ info, config }: ModuleStepParams return; } - const { paths } = config; - pushd(paths.targetProject); + const cwd = config.paths.targetProject; - const status = (await exec(`git status --porcelain`, { stdio: "pipe" })).stdout.trim(); + const status = (await exec(`git status --porcelain`, { cwd, stdio: "pipe" })).stdout.trim(); if (status === "") { console.warn(chalk.yellow("Nothing to commit")); @@ -256,11 +255,10 @@ export async function pushUpdateToTestProject({ info, config }: ModuleStepParams return; } - await setLocalGitUserInfo(); - await exec(`git add .`); - await exec(`git commit -m "Automated update for ${info.mxpackage.name} module [${info.version}]"`); - await exec(`git push origin`); - popd(); + await setLocalGitUserInfo(cwd); + await exec(`git add .`, { cwd }); + await exec(`git commit -m "Automated update for ${info.mxpackage.name} module [${info.version}]"`, { cwd }); + await exec(`git push origin`, { cwd }); } export async function writeModuleVersion({ config, info }: ModuleStepParams): Promise { From 79f8e30f49543d4d63ffcccdd55cc78f412484ff Mon Sep 17 00:00:00 2001 From: Roman Vyakhirev Date: Thu, 29 Oct 2026 14:16:28 +0100 Subject: [PATCH 2/8] chore(automation-utils): replace shelljs file helpers with node:fs Use node:fs/promises for rm, mkdir and cp in automation/utils and the charts-web and data-widgets scripts, and remove shelljs from automation/utils. shell.ts keeps small helpers where node:fs has no direct equivalent: - findFiles: glob that fails when a pattern matches nothing, like shelljs find - move: rename with a copy and remove fallback across file systems, like mv - makeWritableRecursive: chmod -R a+rw zip() now switches directories with process.chdir instead of pushd/popd. --- automation/utils/bin/rui-create-gh-release.ts | 7 +- .../utils/bin/rui-include-oss-in-artifact.ts | 5 +- automation/utils/bin/rui-oss-clearance.ts | 10 +-- automation/utils/package.json | 1 - automation/utils/src/monorepo.ts | 13 ++-- automation/utils/src/mpk.ts | 6 +- automation/utils/src/oss-clearance.ts | 18 ++--- automation/utils/src/shell.ts | 63 +++++++++++------ automation/utils/src/steps.ts | 67 +++++++++---------- .../modules/data-widgets/scripts/start.ts | 4 +- .../charts-web/scripts/build.mts | 24 ++++--- pnpm-lock.yaml | 14 ---- 12 files changed, 119 insertions(+), 113 deletions(-) diff --git a/automation/utils/bin/rui-create-gh-release.ts b/automation/utils/bin/rui-create-gh-release.ts index 412269ffe0..88146dc43a 100755 --- a/automation/utils/bin/rui-create-gh-release.ts +++ b/automation/utils/bin/rui-create-gh-release.ts @@ -4,7 +4,7 @@ import { updateChangelogsAndCreatePR } from "../src/changelog.ts"; import { gh } from "../src/github.ts"; import { addRemoteWithAuthentication } from "../src/index.ts"; import { getPublishedInfo } from "../src/package-info.ts"; -import { exec, find } from "../src/shell.ts"; +import { exec, findFiles } from "../src/shell.ts"; async function resolveChangelogBranch(releaseTag: string, remoteName: string): Promise { const { stdout } = await exec(`git rev-parse --abbrev-ref HEAD`, { stdio: "pipe" }); @@ -75,10 +75,7 @@ async function main(): Promise { // Create release console.log("Creating Github release..."); - const mpk = find(join(path, "dist", version, "*.mpk")).toString(); - if (!mpk) { - throw new Error("MPK file not found"); - } + const [mpk] = findFiles(join(path, "dist", version, "*.mpk")); await gh.createGithubReleaseFrom({ title: `${appName} v${version}`, diff --git a/automation/utils/bin/rui-include-oss-in-artifact.ts b/automation/utils/bin/rui-include-oss-in-artifact.ts index 015df0a0b4..8be75baad4 100755 --- a/automation/utils/bin/rui-include-oss-in-artifact.ts +++ b/automation/utils/bin/rui-include-oss-in-artifact.ts @@ -1,12 +1,11 @@ #!/usr/bin/env node -import { mkdtemp, stat } from "node:fs/promises"; +import { mkdtemp, rm, stat } from "node:fs/promises"; import { tmpdir } from "node:os"; import { join } from "node:path"; import chalk from "chalk"; import { gh } from "../src/github.ts"; import { includeReadmeOssIntoMpk } from "../src/oss-clearance.ts"; -import { rm } from "../src/shell.ts"; /** * This script processes GitHub release artifacts to include READMEOSS HTML files into MPK files. @@ -107,7 +106,7 @@ async function main(): Promise { } finally { // Cleanup temp files console.log(chalk.gray("🧹 Cleaning up temporary files...")); - await rm("-rf", tmpFolder); + await rm(tmpFolder, { recursive: true, force: true }); } } diff --git a/automation/utils/bin/rui-oss-clearance.ts b/automation/utils/bin/rui-oss-clearance.ts index c8eb884b80..045201fde4 100755 --- a/automation/utils/bin/rui-oss-clearance.ts +++ b/automation/utils/bin/rui-oss-clearance.ts @@ -3,7 +3,8 @@ // Enable quiet mode for fetch calls to reduce logging noise process.env.FETCH_QUIET = "true"; -import { homedir } from "node:os"; +import { cp, mkdtemp, rm, stat } from "node:fs/promises"; +import { homedir, tmpdir } from "node:os"; import { basename, join } from "path"; import chalk from "chalk"; import enquirer from "enquirer"; @@ -331,8 +332,6 @@ async function handleIncludeAsEmbeddedAction(release: GitHubDraftRelease, readme printInfo(`Found MPK: ${mpkAsset.name} (${mpkAsset.size} bytes)`); // Create temp folder - const { mkdtemp } = await import("node:fs/promises"); - const { tmpdir } = await import("node:os"); const tmpFolder = await mkdtemp(join(tmpdir(), "mpk-oss-embed-")); const mpkPath = join(tmpFolder, mpkAsset.name); const htmlPath = join(tmpFolder, basename(readmeToInclude)); @@ -344,7 +343,6 @@ async function handleIncludeAsEmbeddedAction(release: GitHubDraftRelease, readme printProgressCheck("Download completed"); // Copy HTML to temp folder - const { cp } = await import("../src/shell.ts"); await cp(readmeToInclude, htmlPath); // Embed HTML into MPK @@ -353,7 +351,6 @@ async function handleIncludeAsEmbeddedAction(release: GitHubDraftRelease, readme printProgressCheck("Merge completed"); // Get modified MPK size - const { stat } = await import("node:fs/promises"); const modifiedMpkStats = await stat(mpkPath); const sizeDiff = modifiedMpkStats.size - mpkAsset.size; printInfo(`Modified MPK size: ${modifiedMpkStats.size} bytes (+${sizeDiff} bytes)`); @@ -400,8 +397,7 @@ async function handleIncludeAsEmbeddedAction(release: GitHubDraftRelease, readme } finally { // Cleanup temp files printProgress("Cleaning up temporary files..."); - const { rm } = await import("../src/shell.ts"); - await rm("-rf", tmpFolder); + await rm(tmpFolder, { recursive: true, force: true }); } } diff --git a/automation/utils/package.json b/automation/utils/package.json index ce59e31868..501ef05acd 100644 --- a/automation/utils/package.json +++ b/automation/utils/package.json @@ -66,7 +66,6 @@ "node-fetch": "^2.7.0", "ora": "^5.4.1", "peggy": "5.1.0", - "shelljs": "^0.8.5", "zod": "^3.25.76" } } diff --git a/automation/utils/src/monorepo.ts b/automation/utils/src/monorepo.ts index dcfb4f6ed5..a2f9575f0b 100644 --- a/automation/utils/src/monorepo.ts +++ b/automation/utils/src/monorepo.ts @@ -1,6 +1,8 @@ +import { cp, mkdir } from "node:fs/promises"; +import { basename } from "node:path"; import enquirer from "enquirer"; import { oraPromise } from "./cli-utils.ts"; -import { cp, exec, find, mkdir } from "./shell.ts"; +import { exec, findFiles } from "./shell.ts"; const { prompt } = enquirer; @@ -40,14 +42,15 @@ export async function resolvePackagePath(npmPackageName: string): Promise { const packages = await listPackages(packageNames); - const paths = [...find(packages.map(p => `${p.path}/dist/${p.version}/*.mpk`))]; - return paths; + return findFiles(...packages.map(p => `${p.path}/dist/${p.version}/*.mpk`)); } export async function copyMpkFiles(packageNames: string[], dest: string): Promise { const paths = await getMpkPaths(packageNames); - mkdir("-p", dest); - cp(paths, dest); + await mkdir(dest, { recursive: true }); + for (const path of paths) { + await cp(path, `${dest}/${basename(path)}`); + } } export async function selectPackage(): Promise { diff --git a/automation/utils/src/mpk.ts b/automation/utils/src/mpk.ts index d997cb3796..188354f5c7 100644 --- a/automation/utils/src/mpk.ts +++ b/automation/utils/src/mpk.ts @@ -1,6 +1,6 @@ import { basename, join } from "path"; import type { ModuleInfo } from "./package-info.ts"; -import { exec, find } from "./shell.ts"; +import { exec, findFiles } from "./shell.ts"; import type { Version } from "./version.ts"; async function ensureMxBuildDockerImageExists(version: string): Promise { @@ -28,7 +28,7 @@ export async function createModuleMpkInDocker( console.log(`Creating module ${moduleName} using mxbuild:${version}...`); // Build testProject via mxbuild - const mprPath = find(`${sourceDir}/*.mpr`)[0]; + const [mprPath] = findFiles(`${sourceDir}/*.mpr`); const projectFile = basename(mprPath); const args = [ // update widgets @@ -61,5 +61,5 @@ export async function createMPK(tmpFolder: string, info: ModuleInfo, excludeFile info.marketplace.minimumMXVersion, excludeFilesRegExp ); - return find(join(tmpFolder, info.mpkName))[0]; + return findFiles(join(tmpFolder, info.mpkName))[0]; } diff --git a/automation/utils/src/oss-clearance.ts b/automation/utils/src/oss-clearance.ts index 65cf1f56eb..56ae320732 100644 --- a/automation/utils/src/oss-clearance.ts +++ b/automation/utils/src/oss-clearance.ts @@ -1,12 +1,12 @@ import { createHash } from "node:crypto"; import { createReadStream } from "node:fs"; -import { mkdtemp, stat } from "node:fs/promises"; +import { cp, mkdir, mkdtemp, rm, stat } from "node:fs/promises"; import { homedir, tmpdir } from "node:os"; import { pipeline } from "node:stream/promises"; import { basename, join, parse } from "path"; import { globSync } from "glob"; import type { GitHubReleaseAsset } from "./github.ts"; -import { chmod, cp, exec, mkdir, mv, rm, unzip, zip } from "./shell.ts"; +import { exec, makeWritableRecursive, move, unzip, zip } from "./shell.ts"; export async function computeSha256(filePath: string): Promise { const hash = createHash("sha256"); @@ -64,7 +64,7 @@ export async function createSBomGeneratorFolderStructure( ): Promise<[folder: string, assetPath: string]> { const tmpFolder = await mkdtemp(join(tmpdir(), "tmp_OSS_Clearance_Artifacts_")); const artifactsFolder = join(tmpFolder, "SBOM_GENERATOR", assetNameAndVersion); - await mkdir("-p", artifactsFolder); + await mkdir(artifactsFolder, { recursive: true }); return [tmpFolder, join(artifactsFolder, `${assetNameAndVersion}.mpk`)]; } @@ -92,10 +92,10 @@ export async function generateSBomArtifactsInFolder( const ossArtifactZip = join(resultsFolder, archiveName); // move to final destination - await mv(ossArtifactZip, finalPath); + await move(ossArtifactZip, finalPath); // removing tmp folder - await rm("-rf", tmpFolder); + await rm(tmpFolder, { recursive: true, force: true }); } export async function includeReadmeOssIntoMpk(readmeOssPath: string, mpkPath: string): Promise { @@ -103,16 +103,16 @@ export async function includeReadmeOssIntoMpk(readmeOssPath: string, mpkPath: st const unzipTarget = join(mpkEntry.dir, "tmp"); // unzip - rm("-rf", unzipTarget); + await rm(unzipTarget, { recursive: true, force: true }); await unzip(mpkPath, unzipTarget); - chmod("-R", "a+rw", unzipTarget); + await makeWritableRecursive(unzipTarget); // Copy the READMEOSS file to the target directory - cp(readmeOssPath, unzipTarget); + await cp(readmeOssPath, join(unzipTarget, basename(readmeOssPath))); // zip it back await zip(unzipTarget, mpkPath); // remove tmp folder - rm("-rf", unzipTarget); + await rm(unzipTarget, { recursive: true, force: true }); } diff --git a/automation/utils/src/shell.ts b/automation/utils/src/shell.ts index 76975f2525..a011fa4ad1 100644 --- a/automation/utils/src/shell.ts +++ b/automation/utils/src/shell.ts @@ -1,17 +1,8 @@ +import { globSync } from "node:fs"; +import { access, chmod, cp, lstat, readdir, rename, rm } from "node:fs/promises"; +import { join } from "node:path"; import crossZip from "cross-zip"; import execa from "execa"; -import shelljs from "shelljs"; - -// shelljs is CommonJS, so named imports are not available under native ESM -const { config } = shelljs; - -// Enable fast fail for all shelljs commands -config.fatal = true; -// Only the file system helpers in use are exported; commands run through execa (see exec below). -// KNOWN ISSUES: -// - mv don't throw error https://github.com/shelljs/shelljs/issues/878 -export const { chmod, cp, find, mkdir, mv, rm } = shelljs; -const { ls, popd, pushd } = shelljs; export function exec(command: string, options?: execa.Options): execa.ExecaChildProcess { const { stdio = "inherit", ...execaOptions } = options ?? {}; @@ -19,19 +10,53 @@ export function exec(command: string, options?: execa.Options): execa.ExecaChild return execa(command, { shell: true, stdio, ...execaOptions }); } -export function ensureFileExists(file: string): void { - const silentState = config.silent; - config.silent = true; - ls(file); - config.silent = silentState; +export async function ensureFileExists(file: string): Promise { + await access(file); +} + +/** Expand glob patterns, failing when a pattern matches nothing. */ +export function findFiles(...patterns: string[]): string[] { + return patterns.flatMap(pattern => { + const matches = globSync(pattern); + if (matches.length === 0) { + throw new Error(`No files match '${pattern}'`); + } + return matches; + }); +} + +/** Move a file or directory, falling back to copy and remove when rename crosses file systems. */ +export async function move(source: string, dest: string): Promise { + try { + await rename(source, dest); + } catch (error) { + if ((error as NodeJS.ErrnoException).code !== "EXDEV") { + throw error; + } + await cp(source, dest, { recursive: true }); + await rm(source, { recursive: true, force: true }); + } +} + +/** Add read and write permissions for everyone to a directory and everything inside it (`chmod -R a+rw`). */ +export async function makeWritableRecursive(dir: string): Promise { + const entries = await readdir(dir, { recursive: true }); + for (const path of [dir, ...entries.map(entry => join(dir, entry))]) { + const stats = await lstat(path); + if (!stats.isSymbolicLink()) { + // eslint-disable-next-line no-bitwise -- permission bits are a bitmask + await chmod(path, stats.mode | 0o666); + } + } } export async function zip(dir: string, fileName: string): Promise { return new Promise((resolve, reject) => { // cross-zip has no cwd option, it zips relative to the process directory - pushd("-q", dir); + const cwd = process.cwd(); + process.chdir(dir); crossZip.zip(".", fileName, err => { - popd("-q"); + process.chdir(cwd); if (err) { reject(err); } else { diff --git a/automation/utils/src/steps.ts b/automation/utils/src/steps.ts index d3b5dad673..971611d42c 100644 --- a/automation/utils/src/steps.ts +++ b/automation/utils/src/steps.ts @@ -1,5 +1,5 @@ -import { readFile, writeFile } from "node:fs/promises"; -import { dirname, join, parse, relative, resolve } from "path"; +import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises"; +import { basename, dirname, join, parse, relative, resolve } from "path"; import chalk from "chalk"; import { type CommonBuildConfig, @@ -13,7 +13,7 @@ import { copyMpkFiles, getMpkPaths } from "./monorepo.ts"; import { createModuleMpkInDocker } from "./mpk.ts"; import type { ModuleInfo, PackageInfo, WidgetInfo } from "./package-info.ts"; import { addFilesToPackageXml, type PackageType } from "./package-xml.ts"; -import { chmod, cp, ensureFileExists, exec, mkdir, rm, unzip, zip } from "./shell.ts"; +import { ensureFileExists, exec, makeWritableRecursive, move, unzip, zip } from "./shell.ts"; type Step = (params: { info: Info; config: Config }) => Promise; @@ -39,7 +39,7 @@ export const logStep = (name: string): void => console.info(`[step]: ${name}`); export async function removeDist({ config }: CommonStepParams): Promise { logStep("Remove dist"); - rm("-rf", config.paths.dist); + await rm(config.paths.dist, { recursive: true, force: true }); } export async function cloneTestProject({ info, config }: CommonStepParams): Promise { @@ -47,7 +47,7 @@ export async function cloneTestProject({ info, config }: CommonStepParams): Prom const { testProject } = info; const clone = process.env.CI ? cloneRepoShallow : cloneRepo; - rm("-rf", config.paths.targetProject); + await rm(config.paths.targetProject, { recursive: true, force: true }); await clone({ remoteUrl: testProject!.githubUrl, branch: testProject!.branchName, @@ -86,10 +86,10 @@ export function copyFilesToMpk( console.log(`Input MPK: ${relative(paths.package, mpk)}`); - ensureFileExists(output.files.mpk); + await ensureFileExists(output.files.mpk); - rm("-rf", target); - mkdir("-p", target); + await rm(target, { recursive: true, force: true }); + await mkdir(target, { recursive: true }); console.info("Unzip module mpk"); await unzip(mpk, target); @@ -99,8 +99,8 @@ export function copyFilesToMpk( const dest = resolve(target, file.pkgPath); console.info(`Copy ${join(file.filePath)} to ${join(file.pkgPath)}`); - mkdir("-p", dirname(dest)); - cp(source, dest); + await mkdir(dirname(dest), { recursive: true }); + await cp(source, dest); } console.info(`Update file entries in package.xml`); @@ -111,9 +111,9 @@ export function copyFilesToMpk( ); console.info("Create module zip archive"); - rm(mpk); + await rm(mpk); await zip(target, mpk); - rm("-rf", target); + await rm(target, { recursive: true, force: true }); }; } @@ -124,17 +124,16 @@ export async function copyThemesourceToProject({ config }: ModuleStepParams): Pr const { output, paths } = config; console.info("Remove module themesource in targetProject"); - rm("-rf", output.dirs.themesource); + await rm(output.dirs.themesource, { recursive: true, force: true }); console.info("Copy module themesource to targetProject"); - mkdir("-p", output.dirs.themesource); - cp("-R", `${paths.themesource}/*`, output.dirs.themesource); + await cp(paths.themesource, output.dirs.themesource, { recursive: true }); } export function copyActionsFiles(files: string[]): (params: ModuleStepParams) => Promise { return async ({ config }) => { logStep("Copy JS Action(s) files"); const { paths, output } = config; - mkdir("-p", join(output.dirs.javascriptsource, "actions")); + await mkdir(join(output.dirs.javascriptsource, "actions"), { recursive: true }); for (const file of files) { const src = join(paths.javascriptsource, "actions", file); @@ -175,28 +174,30 @@ async function insertWidgetsIntoMpk( const packageXml = join(tmpDir, "package.xml"); const packageFilePaths = widgetPaths.map(p => `widgets/${parse(p).base}`); - rm("-rf", tmpDir); + await rm(tmpDir, { recursive: true, force: true }); console.info("Unzip module mpk"); await unzip(mpk, tmpDir); - mkdir("-p", widgetsOut); - chmod("-R", "a+rw", tmpDir); + await mkdir(widgetsOut, { recursive: true }); + await makeWritableRecursive(tmpDir); console.info(`Add ${widgetPaths.length} widgets to ${mpkEntry.base}`); - cp(widgetPaths, widgetsOut); + for (const widgetPath of widgetPaths) { + await cp(widgetPath, join(widgetsOut, basename(widgetPath))); + } if (additionalFiles) { for (const { src, destRelative } of additionalFiles) { - cp(src, join(tmpDir, destRelative)); + await cp(src, join(tmpDir, destRelative)); } } console.info(`Add file entries to package.xml`); await addFilesToPackageXml(packageXml, packageFilePaths, "modelerProject"); - rm(mpk); + await rm(mpk); console.info("Create module zip archive"); await zip(tmpDir, mpk); - rm("-rf", tmpDir); + await rm(tmpDir, { recursive: true, force: true }); } export async function addWidgetsToMpk({ config }: ModuleStepParams): Promise { @@ -229,10 +230,8 @@ export async function moveModuleToDist({ info, config }: ModuleStepParams): Prom const { output, paths } = config; console.info(`Move ${info.mpkName} to dist`); - mkdir("-p", join(paths.dist, info.version.format())); - // Can't use mv because of https://github.com/shelljs/shelljs/issues/878 - cp(output.files.modulePackage, output.files.mpk); - rm(output.files.modulePackage); + await mkdir(join(paths.dist, info.version.format()), { recursive: true }); + await move(output.files.modulePackage, output.files.mpk); } export async function pushUpdateToTestProject({ info, config }: ModuleStepParams): Promise { @@ -264,7 +263,7 @@ export async function pushUpdateToTestProject({ info, config }: ModuleStepParams export async function writeModuleVersion({ config, info }: ModuleStepParams): Promise { logStep("Write module version"); - mkdir("-p", config.output.dirs.themesource); + await mkdir(config.output.dirs.themesource, { recursive: true }); await writeFile(join(config.output.dirs.themesource, ".version"), info.version.format()); } @@ -274,9 +273,9 @@ export async function copyModuleLicense({ config }: ModuleStepParams): Promise { @@ -284,10 +283,10 @@ export async function writeVersionAndLicenseToJSActions({ config, info }: Module const { paths, output } = config; const license = join(paths.package, "LICENSE"); - ensureFileExists(license); + await ensureFileExists(license); - mkdir("-p", output.dirs.javascriptsource); - cp(license, output.dirs.javascriptsource); + await mkdir(output.dirs.javascriptsource, { recursive: true }); + await cp(license, join(output.dirs.javascriptsource, "LICENSE")); await writeFile(join(config.output.dirs.javascriptsource, ".version"), info.version.format()); } diff --git a/packages/modules/data-widgets/scripts/start.ts b/packages/modules/data-widgets/scripts/start.ts index f3d5f796cd..51e6d79f57 100755 --- a/packages/modules/data-widgets/scripts/start.ts +++ b/packages/modules/data-widgets/scripts/start.ts @@ -1,14 +1,14 @@ #!/usr/bin/env node +import { mkdir } from "node:fs/promises"; import { join } from "path"; import concurrently from "concurrently"; -import { mkdir } from "@mendix/automation-utils/shell"; import { getModuleConfigs } from "@mendix/automation-utils/utils"; async function main(): Promise { const [, config] = await getModuleConfigs(process.cwd()); - mkdir("-p", config.paths.targetProject); + await mkdir(config.paths.targetProject, { recursive: true }); await concurrently( [ diff --git a/packages/pluggableWidgets/charts-web/scripts/build.mts b/packages/pluggableWidgets/charts-web/scripts/build.mts index 64742ed7ab..031a1a1a60 100755 --- a/packages/pluggableWidgets/charts-web/scripts/build.mts +++ b/packages/pluggableWidgets/charts-web/scripts/build.mts @@ -1,9 +1,10 @@ #!/usr/bin/env node -import { cp, mkdir, rm, unzip, zip } from "@mendix/automation-utils/shell"; +import { unzip, zip } from "@mendix/automation-utils/shell"; import { logStep, removeDist, runWidgetSteps, type WidgetStepParams } from "@mendix/automation-utils/steps"; import { getWidgetInfo, listPackages } from "@mendix/automation-utils/utils"; -import { dirname, join } from "node:path"; +import { cp, mkdir, rm } from "node:fs/promises"; +import { basename, dirname, join } from "node:path"; // Charts specific steps @@ -16,7 +17,8 @@ async function repackChartWidgets({ config }: WidgetStepParams): Promise { const packages = await listPackages(dependencies); const widgets = await Promise.all(packages.map(({ path }) => getWidgetInfo(path))); - mkdir("-p", [paths.tmp, dirname(output.files.mpk)]); + await mkdir(paths.tmp, { recursive: true }); + await mkdir(dirname(output.files.mpk), { recursive: true }); console.info("Unpacking mpks and create correct file tree..."); for (const pkg of widgets) { @@ -24,17 +26,17 @@ async function repackChartWidgets({ config }: WidgetStepParams): Promise { const contentDir = join(paths.tmp, pkg.mxpackage.name); const pkgSource = join(contentDir, "com"); const pkgXml = join(contentDir, "package.xml"); - mkdir("-p", contentDir); + await mkdir(contentDir, { recursive: true }); await unzip(pkg.mpk, contentDir); - cp("-r", pkgSource, paths.tmp); - rm("-rf", pkgSource); - rm(pkgXml); + await cp(pkgSource, join(paths.tmp, "com"), { recursive: true }); + await rm(pkgSource, { recursive: true, force: true }); + await rm(pkgXml); } console.log("Copying package.xml..."); - cp(join(paths.package, "src", "package.xml"), join(paths.tmp, "package.xml")); + await cp(join(paths.package, "src", "package.xml"), join(paths.tmp, "package.xml")); console.log("Copying License.txt..."); - cp(join(paths.package, "../../../LICENSE"), join(paths.tmp, "License.txt")); + await cp(join(paths.package, "../../../LICENSE"), join(paths.tmp, "License.txt")); console.log("Creating mpk..."); await zip(paths.tmp, output.files.mpk); } @@ -49,8 +51,8 @@ async function main(): Promise { if (copyToProject) { logStep("Copy widget to targetProject"); const dir = join(config.paths.targetProject, "widgets"); - mkdir("-p", dir); - cp(config.output.files.mpk, dir); + await mkdir(dir, { recursive: true }); + await cp(config.output.files.mpk, join(dir, basename(config.output.files.mpk))); } } ] diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 419e59d02e..64940e07f2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -220,9 +220,6 @@ importers: peggy: specifier: 5.1.0 version: 5.1.0 - shelljs: - specifier: ^0.8.5 - version: 0.8.5 zod: specifier: ^3.25.76 version: 3.25.76 @@ -10436,11 +10433,6 @@ packages: resolution: {integrity: sha512-Jex+xw5Mg2qMZL3qnzXIfaxEtBaC4n7xifqaqtrZDdlheR70OGkydrPJWT0V1cA1k3nanC86x9FwAmQl6w3Klw==} engines: {node: '>=18'} - shelljs@0.8.5: - resolution: {integrity: sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==} - engines: {node: '>=4'} - hasBin: true - shelljs@0.9.2: resolution: {integrity: sha512-S3I64fEiKgTZzKCC46zT/Ib9meqofLrQVbpSswtjFfAVDW+AZ54WTnAM/3/yENoxz/V1Cy6u3kiiEbQ4DNphvw==} engines: {node: '>=18'} @@ -20153,12 +20145,6 @@ snapshots: execa: 5.1.1 fast-glob: 3.3.3 - shelljs@0.8.5: - dependencies: - glob: 7.2.3 - interpret: 1.4.0 - rechoir: 0.6.2 - shelljs@0.9.2: dependencies: execa: 1.0.0 From 2c15f0e9411e951a6ed460e6d9067c74aebe92f0 Mon Sep 17 00:00:00 2001 From: Roman Vyakhirev Date: Thu, 29 Oct 2026 14:30:22 +0100 Subject: [PATCH 3/8] chore(run-e2e): replace shelljs with node:fs Use node:fs for ls, rm, mkdir, mv, cp, test and cat in run-e2e, spawnSync for `gh auth token` and the themesource chmod, and remove shelljs from run-e2e. shelljs was not in fatal mode here, so a failed cp or mv only printed an error. They now throw; the Atlas theme and core releases in use contain the copied folders. A missing runtime.log is still reported instead of thrown. --- automation/run-e2e/lib/ci.mjs | 8 ++-- automation/run-e2e/lib/dev.mjs | 10 ++-- automation/run-e2e/lib/docker-utils.mjs | 8 ++-- automation/run-e2e/lib/setup-test-project.mjs | 27 +++++------ .../run-e2e/lib/update-test-project.mjs | 46 ++++++++++--------- automation/run-e2e/package.json | 1 - pnpm-lock.yaml | 3 -- 7 files changed, 46 insertions(+), 57 deletions(-) diff --git a/automation/run-e2e/lib/ci.mjs b/automation/run-e2e/lib/ci.mjs index 7c8c97e03b..a51e958fe9 100644 --- a/automation/run-e2e/lib/ci.mjs +++ b/automation/run-e2e/lib/ci.mjs @@ -1,11 +1,11 @@ import c from "ansi-colors"; import findFreePort from "find-free-port"; import { execSync } from "node:child_process"; +import { globSync } from "node:fs"; import { createServer } from "node:net"; import { networkInterfaces } from "node:os"; import { fileURLToPath } from "node:url"; import p from "node:path"; -import sh from "shelljs"; import parseArgs from "yargs-parser"; import { createDeploymentBundle, @@ -20,8 +20,6 @@ import { updateTestProject } from "./update-test-project.mjs"; import { fetchWithReport } from "./utils.mjs"; import * as config from "./config.mjs"; -const { ls } = sh; - // Path to the docker directory (contains docker-compose.yml + Dockerfiles) const DOCKER_DIR = fileURLToPath(new URL("../docker", import.meta.url)); const COMPOSE_FILE = p.join(DOCKER_DIR, "docker-compose.yml"); @@ -114,7 +112,7 @@ async function runWithCompose({ mendixVersion, ip, freePort }) { await prepareImage("mxbuild", mendixVersion); await prepareImage("mxruntime", mendixVersion); - const projectFile = ls(config.mprFileGlob).toString(); + const [projectFile] = globSync(config.mprFileGlob); if (!projectFile) { throw new Error(`No .mpr file found matching ${config.mprFileGlob}`); } @@ -171,7 +169,7 @@ async function runWithDockerRaw({ mendixVersion, ip, freePort }) { const mxbuildImage = await prepareImage("mxbuild", mendixVersion); const mxruntimeImage = await prepareImage("mxruntime", mendixVersion); - const projectFile = ls(config.mprFileGlob).toString(); + const [projectFile] = globSync(config.mprFileGlob); createDeploymentBundle(mxbuildImage, projectFile); runtimeContainerId = await startRuntime(mxruntimeImage, mendixVersion, ip, freePort, { diff --git a/automation/run-e2e/lib/dev.mjs b/automation/run-e2e/lib/dev.mjs index 8e5a872b00..24dca3f86c 100644 --- a/automation/run-e2e/lib/dev.mjs +++ b/automation/run-e2e/lib/dev.mjs @@ -1,17 +1,15 @@ import { spawnSync, execSync } from "node:child_process"; +import { globSync } from "node:fs"; import { delimiter } from "node:path"; import { fileURLToPath } from "node:url"; import parseArgs from "yargs-parser"; import c from "ansi-colors"; import enquirer from "enquirer"; -import sh from "shelljs"; import { setupTestProject } from "./setup-test-project.mjs"; import { updateTestProject } from "./update-test-project.mjs"; import { await200 } from "./utils.mjs"; import * as config from "./config.mjs"; -const { ls, exec } = sh; - export async function dev() { console.log(c.cyan("Run e2e tests in development environment")); @@ -35,9 +33,9 @@ export async function dev() { if (!process.env.GITHUB_TOKEN) { console.log("GITHUB_TOKEN not found. Fetching from GitHub CLI..."); - const result = exec("gh auth token", { silent: true }); + const result = spawnSync("gh", ["auth", "token"], { encoding: "utf-8" }); - if (result.code === 0) { + if (result.status === 0) { process.env.GITHUB_TOKEN = result.stdout.trim(); console.log("Successfully set GITHUB_TOKEN from gh CLI."); } else { @@ -72,7 +70,7 @@ export async function dev() { // Print out Mendix version from MPR file try { - const mprFiles = ls(config.mprFileGlob); + const mprFiles = globSync(config.mprFileGlob); if (mprFiles.length > 0) { const mprFile = mprFiles[0]; try { diff --git a/automation/run-e2e/lib/docker-utils.mjs b/automation/run-e2e/lib/docker-utils.mjs index 81c28e0d92..9ca4fcbaf2 100644 --- a/automation/run-e2e/lib/docker-utils.mjs +++ b/automation/run-e2e/lib/docker-utils.mjs @@ -1,12 +1,9 @@ import { execSync, spawn, spawnSync } from "node:child_process"; -import { existsSync } from "node:fs"; +import { existsSync, readFileSync } from "node:fs"; import p from "node:path"; import { fileURLToPath } from "node:url"; import fetch from "node-fetch"; import c from "ansi-colors"; -import sh from "shelljs"; - -const { cat } = sh; export function getFullImageName(name, mendixVersion) { return `${name}:${mendixVersion}`; @@ -169,7 +166,8 @@ export async function startRuntime(mxruntimeImage, mendixVersion, ip, freePort, if (attempts === 0) { console.log("Runtime didn't start"); console.log("Print runtime.log..."); - console.log(cat("results/runtime.log").toString()); + const runtimeLog = "results/runtime.log"; + console.log(existsSync(runtimeLog) ? readFileSync(runtimeLog, "utf-8") : `${runtimeLog} not found`); throw new Error("Runtime didn't start in time, exiting now..."); } diff --git a/automation/run-e2e/lib/setup-test-project.mjs b/automation/run-e2e/lib/setup-test-project.mjs index 7fa8e94fb1..615aea7cca 100644 --- a/automation/run-e2e/lib/setup-test-project.mjs +++ b/automation/run-e2e/lib/setup-test-project.mjs @@ -1,23 +1,16 @@ #!/usr/bin/env node -import { createWriteStream } from "node:fs"; +import { createWriteStream, existsSync, globSync, mkdirSync, renameSync, rmSync } from "node:fs"; import { join } from "node:path"; -import sh from "shelljs"; import crossZip from "cross-zip"; import { packageMeta, fetchWithReport, usetmp, streamPipe } from "./utils.mjs"; import * as config from "./config.mjs"; -const { ls, mkdir, rm, mv } = sh; - export async function setupTestProject() { console.log("Copying test project from GitHub repository"); - sh.config.silent = true; - const testsFiles = ls(config.testsDir); - sh.config.silent = false; - - if (testsFiles.length !== 0) { + if (existsSync(config.testsDir)) { console.log("Test project directory already exists, cleaning up..."); - rm("-rf", config.testsDir); + rmSync(config.testsDir, { recursive: true, force: true }); } const archivePath = await downloadTestProject( @@ -26,12 +19,16 @@ export async function setupTestProject() { ); try { - mkdir("-p", config.testsDir); + mkdirSync(config.testsDir, { recursive: true }); crossZip.unzipSync(archivePath, config.testsDir); - mv(config.postUnzipProjectDirGlob, config.testProjectDir); - rm("-f", archivePath); + const [unzippedProjectDir] = globSync(config.postUnzipProjectDirGlob); + if (!unzippedProjectDir) { + throw new Error(`No directory matching ${config.postUnzipProjectDirGlob} after unzipping.`); + } + renameSync(unzippedProjectDir, config.testProjectDir); + rmSync(archivePath, { force: true }); - if (ls(config.mprFileGlob).length === 0) { + if (globSync(config.mprFileGlob).length === 0) { throw new Error('Invalid test project retrieved from GitHub: "mpr" file is missing.'); } } catch (e) { @@ -55,7 +52,7 @@ async function downloadTestProject(repository, branch) { ); return downloadedArchivePath; } catch (e) { - rm("-f", downloadedArchivePath); + rmSync(downloadedArchivePath, { force: true }); throw new Error("Cannot find test project in GitHub repository. Try again later.", { cause: e }); } } diff --git a/automation/run-e2e/lib/update-test-project.mjs b/automation/run-e2e/lib/update-test-project.mjs index 5641ecaadf..c5221077c1 100644 --- a/automation/run-e2e/lib/update-test-project.mjs +++ b/automation/run-e2e/lib/update-test-project.mjs @@ -1,15 +1,12 @@ import crossZip from "cross-zip"; import assert from "node:assert/strict"; import { spawnSync } from "node:child_process"; -import { createWriteStream } from "node:fs"; -import { join, resolve } from "node:path"; -import sh from "shelljs"; +import { cpSync, createWriteStream, existsSync, globSync, mkdirSync, rmSync } from "node:fs"; +import { basename, join, resolve } from "node:path"; import * as config from "./config.mjs"; import { fetchGithubRestAPI, fetchWithReport, packageMeta, streamPipe, usetmp } from "./utils.mjs"; import { atlasCoreReleaseUrl } from "./config.mjs"; -const { cp, rm, mkdir, test } = sh; - async function getReleaseByTag(tag) { const url = `${atlasCoreReleaseUrl}/tags/${tag}`; const response = await fetchGithubRestAPI(url); @@ -26,7 +23,7 @@ async function downloadAndExtract(url, downloadPath, extractPath) { } catch (e) { throw new Error(`Unable to download and extract from ${url}`, { cause: e }); } finally { - rm("-f", downloadPath); + rmSync(downloadPath, { force: true }); } } @@ -35,7 +32,9 @@ async function updateAtlasThemeSource() { const tag = `atlas-core-v${version}`; console.log(`Copying Atlas themesource files from Atlas Core release ${tag}`); - rm("-rf", config.atlasDirsToRemove); + for (const dir of config.atlasDirsToRemove) { + rmSync(dir, { recursive: true, force: true }); + } const release = await getReleaseByTag(tag); if (!release.assets || release.assets.length === 0) { @@ -48,24 +47,24 @@ async function updateAtlasThemeSource() { await downloadAndExtract(browser_download_url, downloadedPath, outPath); const themeSourcePath = join(outPath, "themesource"); - if (!test("-d", themeSourcePath)) { + if (!existsSync(themeSourcePath)) { console.log(`Directory not found: ${themeSourcePath}. Creating it.`); - mkdir("-p", themeSourcePath); + mkdirSync(themeSourcePath, { recursive: true }); } - cp("-r", themeSourcePath, config.testProjectDir); + cpSync(themeSourcePath, join(config.testProjectDir, "themesource"), { recursive: true }); // Fix file permissions to ensure Docker can write to theme files // The Atlas theme files are copied with read-only permissions // but mxbuild needs to write to some generated files during build - sh.exec(`chmod -R +w "${config.testProjectDir}/themesource"`, { silent: true }); + spawnSync("chmod", ["-R", "+w", join(config.testProjectDir, "themesource")]); } async function updateAtlasTheme() { const tag = packageMeta.testProject?.atlasThemeTag ?? config.defaultAtlasThemeTag; console.log(`Copying Atlas theme files from Atlas UI theme release ${tag}`); - rm("-rf", "tests/testProject/theme"); + rmSync("tests/testProject/theme", { recursive: true, force: true }); // Fetch the specific release by tag from GitHub API const release = await getReleaseByTag(tag); @@ -79,16 +78,14 @@ async function updateAtlasTheme() { await downloadAndExtract(browser_download_url, downloadedPath, outPath); const themePath = join(outPath, "theme"); - if (!test("-d", themePath)) { + if (!existsSync(themePath)) { console.log(`Directory not found: ${themePath}. Creating it.`); - mkdir("-p", themePath); + mkdirSync(themePath, { recursive: true }); } - const webPath = join(outPath, "web"); - const nativePath = join(outPath, "native"); - cp("-r", webPath, themePath); - cp("-r", nativePath, themePath); + cpSync(join(outPath, "web"), join(themePath, "web"), { recursive: true }); + cpSync(join(outPath, "native"), join(themePath, "native"), { recursive: true }); - cp("-r", themePath, config.testProjectDir); + cpSync(themePath, join(config.testProjectDir, "theme"), { recursive: true }); } async function runReleaseScript() { @@ -113,10 +110,15 @@ async function runReleaseScript() { spawnSync(command, args, { stdio: "inherit", shell: true }); console.log("Copying widget mpk."); - const mpkPath = `dist/${version}/*.mpk`; + const mpkPaths = globSync(`dist/${version}/*.mpk`); + if (mpkPaths.length === 0) { + throw new Error(`No mpk found in dist/${version}`); + } const outDir = join(config.testProjectDir, "widgets"); - mkdir("-p", outDir); - cp("-f", mpkPath, outDir); + mkdirSync(outDir, { recursive: true }); + for (const mpkPath of mpkPaths) { + cpSync(mpkPath, join(outDir, basename(mpkPath))); + } } async function runUpdateProjectScript() { diff --git a/automation/run-e2e/package.json b/automation/run-e2e/package.json index cca12887a6..4bbc4ecfef 100644 --- a/automation/run-e2e/package.json +++ b/automation/run-e2e/package.json @@ -28,7 +28,6 @@ "enquirer": "^2.4.1", "find-free-port": "^2.0.0", "node-fetch": "^3.3.2", - "shelljs": "^0.10.0", "yargs-parser": "^22.0.0" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 64940e07f2..69bc794bfc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -116,9 +116,6 @@ importers: node-fetch: specifier: ^3.3.2 version: 3.3.2 - shelljs: - specifier: ^0.10.0 - version: 0.10.0 yargs-parser: specifier: ^22.0.0 version: 22.0.0 From b104dc4cc27acb1688db615ea3b8cc075aec42d2 Mon Sep 17 00:00:00 2001 From: Roman Vyakhirev Date: Thu, 29 Oct 2026 16:25:54 +0100 Subject: [PATCH 4/8] chore: drop unused shx dependency of pluggable-widgets-tools pluggable-widgets-tools depends on shx, which pulls in shelljs 0.9.2, but neither the tools nor this repo call it. Remove it with a pnpm override, like the other unused tools dependencies. The tools still use shelljs 0.10.0 in their rollup config until a release without it is available. --- package.json | 1 + pnpm-lock.yaml | 127 +------------------------------------------------ 2 files changed, 3 insertions(+), 125 deletions(-) diff --git a/package.json b/package.json index c885b3ca3f..36af76107d 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "@mendix/pluggable-widgets-tools>eslint-plugin-react": "-", "@mendix/pluggable-widgets-tools>eslint-plugin-react-hooks": "-", "@mendix/pluggable-widgets-tools>prettier": "-", + "@mendix/pluggable-widgets-tools>shx": "-", "@prettier/plugin-xml": ">=3.4.1", "@testing-library/dom": "^10.4.1", "@testing-library/react": "^16.3.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 69bc794bfc..cd1ab0e78c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -19,6 +19,7 @@ overrides: '@mendix/pluggable-widgets-tools>eslint-plugin-react': '-' '@mendix/pluggable-widgets-tools>eslint-plugin-react-hooks': '-' '@mendix/pluggable-widgets-tools>prettier': '-' + '@mendix/pluggable-widgets-tools>shx': '-' '@prettier/plugin-xml': '>=3.4.1' '@testing-library/dom': ^10.4.1 '@testing-library/react': ^16.3.2 @@ -6921,10 +6922,6 @@ packages: engines: {node: '>=10.14', npm: '>=6', yarn: '>=1'} hasBin: true - cross-spawn@6.0.6: - resolution: {integrity: sha512-VqCUuhcd1iB+dsv8gxPttb5iZh/D0iubSP21g36KXdEuf6I5JiioesUVjpCdHV9MZRUfVFlvwtIUyPfxo5trtw==} - engines: {node: '>=4.8'} - cross-spawn@7.0.6: resolution: {integrity: sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==} engines: {node: '>= 8'} @@ -7672,10 +7669,6 @@ packages: resolution: {integrity: sha512-CRT1WTyuQoD771GW56XEZFQ/ZoSfWid1alKGDYMmkt2yl8UXrVR4pspqWNEcqKvVIzg6PAltWjxcSSPrboA4iA==} engines: {node: '>=18.0.0'} - execa@1.0.0: - resolution: {integrity: sha512-adbxcyWV46qiHyvSp50TKt05tB4tK3HcmF7/nxfAdhnox83seTDbwnaqKO4sXRy7roHAIFqJP/Rw/AuEbX61LA==} - engines: {node: '>=6'} - execa@5.1.1: resolution: {integrity: sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==} engines: {node: '>=10'} @@ -7928,10 +7921,6 @@ packages: resolution: {integrity: sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==} engines: {node: '>= 0.4'} - get-stream@4.1.0: - resolution: {integrity: sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==} - engines: {node: '>=6'} - get-stream@6.0.1: resolution: {integrity: sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==} engines: {node: '>=10'} @@ -8273,10 +8262,6 @@ packages: resolution: {integrity: sha512-4gd7VpWNQNB4UKKCFFVcp1AVv+FMOgs9NKzjHKusc8jTMhd5eL1NqQqOpE0KzMds804/yHlglp3uxgluOqAPLw==} engines: {node: '>= 0.4'} - interpret@1.4.0: - resolution: {integrity: sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==} - engines: {node: '>= 0.10'} - invariant@2.2.4: resolution: {integrity: sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==} @@ -8440,10 +8425,6 @@ packages: resolution: {integrity: sha512-ISWac8drv4ZGfwKl5slpHG9OwPNty4jOWPRIhBpxOoD+hqITiwuipOQ2bNthAzwA3B4fIjO4Nln74N0S9byq8A==} engines: {node: '>= 0.4'} - is-stream@1.1.0: - resolution: {integrity: sha512-uQPm8kcs47jx38atAcWTVxyltQYoPT68y9aWYdV6yWXSyW8mzSat0TL6CiWdZeCdF3KrAvpVtnHbTv4RN+rqdQ==} - engines: {node: '>=0.10.0'} - is-stream@2.0.1: resolution: {integrity: sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==} engines: {node: '>=8'} @@ -9205,9 +9186,6 @@ packages: next-tick@1.1.0: resolution: {integrity: sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==} - nice-try@1.0.5: - resolution: {integrity: sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==} - node-abi@3.94.0: resolution: {integrity: sha512-W5ZNO5KRPB5TkYmGVD9F6YqhsglXJzE6etpbmT+f6EQElhiX/UTG551cnsRGvLG3fyZEg9HwaDmNmj5nwJ4z9g==} engines: {node: '>=10'} @@ -9267,10 +9245,6 @@ packages: resolution: {integrity: sha512-IciCE3SY3uE84Ld8WZU23gAPPV9rIYod4F+rc+vJ7h7cwAJt9Vk6TVsK60ry7Uj3SRS3bqRRIGuTp9YVlk6WNA==} engines: {node: ^20.17.0 || >=22.9.0} - npm-run-path@2.0.2: - resolution: {integrity: sha512-lJxZYlT4DW/bRUtFh1MQIWqmLwQfAxnqWG4HhEdjMlkrJYnJn0Jrr2u3mgxqaWsdiBc76TYkTG/mhrnYTuzfHw==} - engines: {node: '>=4'} - npm-run-path@4.0.1: resolution: {integrity: sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==} engines: {node: '>=8'} @@ -9433,10 +9407,6 @@ packages: resolution: {integrity: sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==} engines: {node: '>=0.10.0'} - path-key@2.0.1: - resolution: {integrity: sha512-fEHGKCSmUSDPv4uoj8AlD+joPlq3peND+HRYyxFz4KPw4z926S/b8rIuFs2FYJg3BwsxJf6A9/3eIdLaYC+9Dw==} - engines: {node: '>=4'} - path-key@3.1.1: resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==} engines: {node: '>=8'} @@ -10132,10 +10102,6 @@ packages: resolution: {integrity: sha512-dEWRjcINDu/F4l2dYx57ugBtD7HV9KXESyxhzw/MqWLeglJrsjJKqACPyUPg+6AF8mIgm+Zi0dZ3ACoIg+QtpA==} engines: {node: '>= 4'} - rechoir@0.6.2: - resolution: {integrity: sha512-HFM8rkZ+i3zrV+4LQjwQ0W+ez98pApMGM3HUrN04j3CqzPOzl9nmP15Y8YXNm8QHGv/eacOVEjqhmWpkRV0NAw==} - engines: {node: '>= 0.10'} - recursive-copy@2.0.14: resolution: {integrity: sha512-K8WNY8f8naTpfbA+RaXmkaQuD1IeW9EgNEfyGxSqqTQukpVtoOKros9jUqbpEsSw59YOmpd8nCBgtqJZy5nvog==} @@ -10410,18 +10376,10 @@ packages: shallow-copy@0.0.1: resolution: {integrity: sha512-b6i4ZpVuUxB9h5gfCxPiusKYkqTMOjEbBs4wMaFbkfia4yFv92UKZ6Df8WXcKbn08JNL/abvg3FnMAOfakDvUw==} - shebang-command@1.2.0: - resolution: {integrity: sha512-EV3L1+UQWGor21OmnvojK36mhg+TyIKDh3iFBKBohr5xeXIhNBcx8oWdgkTEEQ+BEFFYdLRuqMfd5L84N1V5Vg==} - engines: {node: '>=0.10.0'} - shebang-command@2.0.0: resolution: {integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==} engines: {node: '>=8'} - shebang-regex@1.0.0: - resolution: {integrity: sha512-wpoSFAxys6b2a2wHZ1XpDSgD7N9iVjg29Ph9uV/uaP9Ex/KXlkTZTeddxDPSYQpgvzKLGJke2UU0AzoGCjNIvQ==} - engines: {node: '>=0.10.0'} - shebang-regex@3.0.0: resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} engines: {node: '>=8'} @@ -10430,19 +10388,9 @@ packages: resolution: {integrity: sha512-Jex+xw5Mg2qMZL3qnzXIfaxEtBaC4n7xifqaqtrZDdlheR70OGkydrPJWT0V1cA1k3nanC86x9FwAmQl6w3Klw==} engines: {node: '>=18'} - shelljs@0.9.2: - resolution: {integrity: sha512-S3I64fEiKgTZzKCC46zT/Ib9meqofLrQVbpSswtjFfAVDW+AZ54WTnAM/3/yENoxz/V1Cy6u3kiiEbQ4DNphvw==} - engines: {node: '>=18'} - hasBin: true - shifty@3.0.6: resolution: {integrity: sha512-rRt3IbKHsDsXY1cAcbp26gJQMK93N6wczvWeGIfljEsaM5JgcaqPAG2xNXQH9NsNJNgmAVXp+FVXdJIUk7x8DQ==} - shx@0.4.0: - resolution: {integrity: sha512-Z0KixSIlGPpijKgcH6oCMCbltPImvaKy0sGH8AkLRXw1KyzpKtaCTizP2xen+hNDqVF4xxgvA0KXSb9o4Q6hnA==} - engines: {node: '>=18'} - hasBin: true - side-channel-list@1.0.1: resolution: {integrity: sha512-mjn/0bi/oUURjc5Xl7IaWi/OJJJumuoJFQJfDDyO46+hBWsfaVM65TBHq2eoZBhzl9EchxOijpkbRC8SVBQU0w==} engines: {node: '>= 0.4'} @@ -10642,10 +10590,6 @@ packages: resolution: {integrity: sha512-3xurFv5tEgii33Zi8Jtp55wEIILR9eh34FAW00PZf+JnSsTmV/ioewSgQl97JHvgjoRGwPShsWm+IdrxB35d0w==} engines: {node: '>=8'} - strip-eof@1.0.0: - resolution: {integrity: sha512-7FCwGGmx8mD5xQd3RPUvnSpUXHM3BWuzjtpD4TXsfcZ9EL4azvVVUscFYwD9nx8Kh+uCBC00XBtAykoMHwTh8Q==} - engines: {node: '>=0.10.0'} - strip-final-newline@2.0.0: resolution: {integrity: sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==} engines: {node: '>=6'} @@ -11137,10 +11081,6 @@ packages: resolution: {integrity: sha512-fvO4ExWMFsqyhG3AiPAObMuY1lxaqgYcxbc49CNdWDDECOJNgQyvsOWVwbZc+qf3rzRtxojBK+CMEv0Ld5CYpw==} engines: {node: '>= 0.4'} - which@1.3.1: - resolution: {integrity: sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==} - hasBin: true - which@2.0.2: resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==} engines: {node: '>= 8'} @@ -12991,7 +12931,6 @@ snapshots: sass: 1.102.0 semver: 7.8.5 shelljs: 0.10.0 - shx: 0.4.0 ts-jest: 29.4.11(@babel/core@7.29.7)(@jest/transform@30.3.0)(@jest/types@30.4.1)(babel-jest@30.3.0(@babel/core@7.29.7))(jest-util@30.4.1)(jest@30.3.0(@types/node@26.6.6)(ts-node@10.9.2(@swc/core@1.15.46)(@types/node@26.6.6)(typescript@5.9.3)))(typescript@5.9.3) ts-node: 10.9.2(@swc/core@1.15.46)(@types/node@26.6.6)(typescript@5.9.3) typescript: 5.9.3 @@ -13085,7 +13024,6 @@ snapshots: sass: 1.102.0 semver: 7.8.5 shelljs: 0.10.0 - shx: 0.4.0 ts-jest: 29.4.11(@babel/core@7.29.7)(@jest/transform@30.3.0)(@jest/types@30.4.1)(babel-jest@30.3.0(@babel/core@7.29.7))(jest-util@30.4.1)(jest@30.3.0(@types/node@26.6.6)(ts-node@10.9.2(@swc/core@1.15.46)(@types/node@26.6.6)(typescript@5.9.3)))(typescript@5.9.3) ts-node: 10.9.2(@swc/core@1.15.46)(@types/node@26.6.6)(typescript@5.9.3) typescript: 5.9.3 @@ -15521,14 +15459,6 @@ snapshots: dependencies: cross-spawn: 7.0.6 - cross-spawn@6.0.6: - dependencies: - nice-try: 1.0.5 - path-key: 2.0.1 - semver: 5.7.2 - shebang-command: 1.2.0 - which: 1.3.1 - cross-spawn@7.0.6: dependencies: path-key: 3.1.1 @@ -16486,16 +16416,6 @@ snapshots: dependencies: eventsource-parser: 3.1.1 - execa@1.0.0: - dependencies: - cross-spawn: 6.0.6 - get-stream: 4.1.0 - is-stream: 1.1.0 - npm-run-path: 2.0.2 - p-finally: 1.0.0 - signal-exit: 3.0.7 - strip-eof: 1.0.0 - execa@5.1.1: dependencies: cross-spawn: 7.0.6 @@ -16814,10 +16734,6 @@ snapshots: dunder-proto: 1.0.1 es-object-atoms: 1.1.2 - get-stream@4.1.0: - dependencies: - pump: 3.0.4 - get-stream@6.0.1: {} get-symbol-description@1.1.0: @@ -17229,8 +17145,6 @@ snapshots: hasown: 2.0.4 side-channel: 1.1.1 - interpret@1.4.0: {} - invariant@2.2.4: dependencies: loose-envify: 1.4.0 @@ -17380,8 +17294,6 @@ snapshots: dependencies: call-bound: 1.0.4 - is-stream@1.1.0: {} - is-stream@2.0.1: {} is-string-blank@1.0.1: {} @@ -18450,8 +18362,6 @@ snapshots: next-tick@1.1.0: {} - nice-try@1.0.5: {} - node-abi@3.94.0: dependencies: semver: 7.8.5 @@ -18505,10 +18415,6 @@ snapshots: semver: 7.8.5 validate-npm-package-name: 7.0.2 - npm-run-path@2.0.2: - dependencies: - path-key: 2.0.1 - npm-run-path@4.0.1: dependencies: path-key: 3.1.1 @@ -18681,8 +18587,6 @@ snapshots: path-is-absolute@1.0.1: {} - path-key@2.0.1: {} - path-key@3.1.1: {} path-parse@1.0.7: {} @@ -19420,6 +19324,7 @@ snapshots: dependencies: end-of-stream: 1.4.5 once: 1.4.0 + optional: true punycode.js@2.3.1: {} @@ -19679,10 +19584,6 @@ snapshots: tiny-invariant: 1.3.3 tslib: 2.8.1 - rechoir@0.6.2: - dependencies: - resolve: 1.22.12 - recursive-copy@2.0.14: dependencies: errno: 0.1.8 @@ -20125,16 +20026,10 @@ snapshots: shallow-copy@0.0.1: {} - shebang-command@1.2.0: - dependencies: - shebang-regex: 1.0.0 - shebang-command@2.0.0: dependencies: shebang-regex: 3.0.0 - shebang-regex@1.0.0: {} - shebang-regex@3.0.0: {} shelljs@0.10.0: @@ -20142,22 +20037,10 @@ snapshots: execa: 5.1.1 fast-glob: 3.3.3 - shelljs@0.9.2: - dependencies: - execa: 1.0.0 - fast-glob: 3.3.3 - interpret: 1.4.0 - rechoir: 0.6.2 - shifty@3.0.6: optionalDependencies: fsevents: 2.3.3 - shx@0.4.0: - dependencies: - minimist: 1.2.8 - shelljs: 0.9.2 - side-channel-list@1.0.1: dependencies: es-errors: 1.3.0 @@ -20394,8 +20277,6 @@ snapshots: strip-bom@4.0.0: {} - strip-eof@1.0.0: {} - strip-final-newline@2.0.0: {} strip-indent@3.0.0: @@ -20942,10 +20823,6 @@ snapshots: gopd: 1.2.0 has-tostringtag: 1.0.2 - which@1.3.1: - dependencies: - isexe: 2.0.0 - which@2.0.2: dependencies: isexe: 2.0.0 From 3ea5a6a0e7e2cad13cc973b0c5e0535fb8c589cb Mon Sep 17 00:00:00 2001 From: Roman Vyakhirev Date: Mon, 9 Nov 2026 14:59:12 +0100 Subject: [PATCH 5/8] chore: remove stale shelljs hoist pattern from .npmrc No code in the repo imports shelljs anymore. The pattern also had no effect, because shamefully-hoist=true already hoists every package to the root. --- .npmrc | 1 - 1 file changed, 1 deletion(-) diff --git a/.npmrc b/.npmrc index ee0e8ed259..691093bec4 100644 --- a/.npmrc +++ b/.npmrc @@ -27,7 +27,6 @@ public-hoist-pattern[]=make-dir # public-hoist-pattern rule. public-hoist-pattern[]=*babel* public-hoist-pattern[]=big.js -public-hoist-pattern[]=*shelljs* public-hoist-pattern[]=*rollup* public-hoist-pattern[]=@types/node public-hoist-pattern[]=@types/big.js From de0ce78f5709ea41e1e7100fd2f84c2871c00bcf Mon Sep 17 00:00:00 2001 From: Roman Vyakhirev Date: Mon, 9 Nov 2026 15:01:34 +0100 Subject: [PATCH 6/8] test(automation-utils): cover the shell.ts file helpers Add node:test specs for ensureFileExists, findFiles, move, makeWritableRecursive and zip/unzip, run by a new test script so CI runs them with the other unit tests. No new dependencies. --- automation/utils/package.json | 3 +- automation/utils/src/__tests__/shell.spec.ts | 129 +++++++++++++++++++ 2 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 automation/utils/src/__tests__/shell.spec.ts diff --git a/automation/utils/package.json b/automation/utils/package.json index 501ef05acd..9a1ccf46b6 100644 --- a/automation/utils/package.json +++ b/automation/utils/package.json @@ -50,7 +50,8 @@ "oss-clearance": "node bin/rui-oss-clearance.ts", "prepare": "tsc", "prepare-release": "node bin/rui-prepare-release.ts", - "start": "tsc --watch" + "start": "tsc --watch", + "test": "node --test \"src/**/*.spec.ts\"" }, "devDependencies": { "@mendix/eslint-config-web-widgets": "workspace:*", diff --git a/automation/utils/src/__tests__/shell.spec.ts b/automation/utils/src/__tests__/shell.spec.ts new file mode 100644 index 0000000000..c2b75c45a3 --- /dev/null +++ b/automation/utils/src/__tests__/shell.spec.ts @@ -0,0 +1,129 @@ +import assert from "node:assert/strict"; +import { existsSync, readdirSync } from "node:fs"; +import { chmod, mkdir, mkdtemp, readFile, rm, stat, symlink, writeFile } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { afterEach, beforeEach, describe, it } from "node:test"; +import { ensureFileExists, findFiles, makeWritableRecursive, move, unzip, zip } from "../shell.ts"; + +let tmp: string; + +beforeEach(async () => { + tmp = await mkdtemp(join(tmpdir(), "automation-utils-shell-")); +}); + +afterEach(async () => { + await rm(tmp, { recursive: true, force: true }); +}); + +async function writeTree(root: string, files: Record): Promise { + for (const [path, content] of Object.entries(files)) { + await mkdir(join(root, path, ".."), { recursive: true }); + await writeFile(join(root, path), content); + } +} + +describe("ensureFileExists", () => { + it("resolves for an existing file", async () => { + await writeTree(tmp, { "a.txt": "a" }); + await ensureFileExists(join(tmp, "a.txt")); + }); + + it("rejects with ENOENT for a missing file", async () => { + await assert.rejects(ensureFileExists(join(tmp, "missing.txt")), { code: "ENOENT" }); + }); +}); + +describe("findFiles", () => { + it("expands every pattern", async () => { + await writeTree(tmp, { "a/one.mpk": "", "b/two.mpk": "", "b/other.txt": "" }); + + const found = findFiles(join(tmp, "a", "*.mpk"), join(tmp, "b", "*.mpk")); + + assert.deepEqual(found, [join(tmp, "a", "one.mpk"), join(tmp, "b", "two.mpk")]); + }); + + it("throws when a pattern matches nothing", async () => { + await writeTree(tmp, { "a/one.mpk": "" }); + + assert.throws(() => findFiles(join(tmp, "a", "*.mpk"), join(tmp, "b", "*.mpk")), /No files match/); + }); +}); + +describe("move", () => { + it("moves a file", async () => { + await writeTree(tmp, { "src.txt": "content" }); + + await move(join(tmp, "src.txt"), join(tmp, "dest.txt")); + + assert.equal(existsSync(join(tmp, "src.txt")), false); + assert.equal(await readFile(join(tmp, "dest.txt"), "utf-8"), "content"); + }); + + it("moves a directory with its contents", async () => { + await writeTree(tmp, { "src/nested/file.txt": "content" }); + + await move(join(tmp, "src"), join(tmp, "dest")); + + assert.equal(existsSync(join(tmp, "src")), false); + assert.equal(await readFile(join(tmp, "dest", "nested", "file.txt"), "utf-8"), "content"); + }); +}); + +describe("makeWritableRecursive", { skip: process.platform === "win32" && "POSIX permission bits" }, () => { + it("adds read and write permissions for everyone and keeps other bits", async () => { + await writeTree(tmp, { "dir/nested/file.txt": "", "dir/script.sh": "" }); + await chmod(join(tmp, "dir", "nested", "file.txt"), 0o400); + await chmod(join(tmp, "dir", "script.sh"), 0o700); + await chmod(join(tmp, "dir", "nested"), 0o700); + + await makeWritableRecursive(join(tmp, "dir")); + + const mode = async (path: string): Promise => ((await stat(join(tmp, path))).mode & 0o777).toString(8); // eslint-disable-line no-bitwise + assert.equal(await mode("dir/nested/file.txt"), "666"); + assert.equal(await mode("dir/script.sh"), "766"); + assert.equal(await mode("dir/nested"), "766"); + }); + + it("does not follow symbolic links", async () => { + await writeTree(tmp, { "outside.txt": "", "dir/file.txt": "" }); + await chmod(join(tmp, "outside.txt"), 0o400); + await symlink(join(tmp, "outside.txt"), join(tmp, "dir", "link.txt")); + + await makeWritableRecursive(join(tmp, "dir")); + + // eslint-disable-next-line no-bitwise + assert.equal(((await stat(join(tmp, "outside.txt"))).mode & 0o777).toString(8), "400"); + }); +}); + +describe("zip and unzip", () => { + it("stores the directory contents at the archive root", async () => { + await writeTree(tmp, { "content/package.xml": "", "content/widgets/a.mpk": "a" }); + const archive = join(tmp, "out.mpk"); + + await zip(join(tmp, "content"), archive); + await unzip(archive, join(tmp, "unzipped")); + + assert.deepEqual(readdirSync(join(tmp, "unzipped")).sort(), ["package.xml", "widgets"]); + assert.equal(await readFile(join(tmp, "unzipped", "widgets", "a.mpk"), "utf-8"), "a"); + }); + + it("restores the working directory after zipping", async () => { + await writeTree(tmp, { "content/a.txt": "a" }); + const cwd = process.cwd(); + + await zip(join(tmp, "content"), join(tmp, "out.zip")); + + assert.equal(process.cwd(), cwd); + }); + + it("restores the working directory when zipping fails", async () => { + await writeTree(tmp, { "content/a.txt": "a" }); + const cwd = process.cwd(); + + await assert.rejects(zip(join(tmp, "content"), join(tmp, "missing-dir", "out.zip"))); + + assert.equal(process.cwd(), cwd); + }); +}); From c2db20089c38565dcfc8d5ebac2358d7132a35b9 Mon Sep 17 00:00:00 2001 From: Roman Vyakhirev Date: Sat, 14 Nov 2026 04:50:19 +0100 Subject: [PATCH 7/8] test(automation-utils): cover the release steps that rebuild mpks --- .../utils/src/__tests__/mpk-archive.spec.ts | 178 ++++++++++++++++++ automation/utils/src/__tests__/shell.spec.ts | 22 +++ 2 files changed, 200 insertions(+) create mode 100644 automation/utils/src/__tests__/mpk-archive.spec.ts diff --git a/automation/utils/src/__tests__/mpk-archive.spec.ts b/automation/utils/src/__tests__/mpk-archive.spec.ts new file mode 100644 index 0000000000..534fb8d76d --- /dev/null +++ b/automation/utils/src/__tests__/mpk-archive.spec.ts @@ -0,0 +1,178 @@ +// Runs the release steps that unzip an mpk, change it and zip it back, against the real +// zip tooling of the machine (`zip`/`unzip` on Linux and macOS, PowerShell on Windows). +// CI runs these on the same runners as the release build. +import assert from "node:assert/strict"; +import { existsSync, readdirSync, statSync } from "node:fs"; +import { chmod, mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { afterEach, beforeEach, describe, it } from "node:test"; +import { includeReadmeOssIntoMpk } from "../oss-clearance.ts"; +import { readXml } from "../package-xml.ts"; +import { unzip, zip } from "../shell.ts"; +import { addTestProjectWidgetsToMpk, copyFilesToMpk, type ModuleStepParams } from "../steps.ts"; + +let tmp: string; + +beforeEach(async () => { + tmp = await mkdtemp(join(tmpdir(), "automation-utils-mpk-")); +}); + +afterEach(async () => { + await rm(tmp, { recursive: true, force: true }); +}); + +const MODULE_PACKAGE_XML = ` + + + + + + + +`; + +async function writeTree(root: string, files: Record): Promise { + for (const [path, content] of Object.entries(files)) { + await mkdir(join(root, path, ".."), { recursive: true }); + await writeFile(join(root, path), content); + } +} + +/** A module mpk like the one mxbuild creates, with a read-only file inside. */ +async function createModuleMpk(mpk: string): Promise { + const content = join(tmp, "module-content"); + await writeTree(content, { + "package.xml": MODULE_PACKAGE_XML, + "DataWidgets.mpr": "mpr", + "themesource/datawidgets/web/main.scss": "// styles" + }); + if (process.platform !== "win32") { + // mxbuild output is read-only; the steps must still be able to rewrite the archive + await chmod(join(content, "themesource", "datawidgets", "web", "main.scss"), 0o444); + } + await zip(content, mpk); + await rm(content, { recursive: true, force: true }); +} + +/** A widget mpk: a zip archive with binary content, nested inside the module mpk. */ +async function createWidgetMpk(mpk: string): Promise { + const content = join(tmp, "widget-content"); + await writeTree(content, { + "package.xml": "", + "com/mendix/widget/web/Gallery.js": "export {}" + }); + await zip(content, mpk); + await rm(content, { recursive: true, force: true }); + return readFile(mpk); +} + +async function listArchive(mpk: string): Promise { + const target = await mkdtemp(join(tmp, "list-")); + await unzip(mpk, target); + return readdirSync(target, { recursive: true, encoding: "utf-8" }) + .filter(entry => statSync(join(target, entry)).isFile()) + .map(entry => entry.replaceAll("\\", "/")) + .sort(); +} + +async function readFromArchive(mpk: string, entry: string): Promise { + const target = await mkdtemp(join(tmp, "read-")); + await unzip(mpk, target); + return readFile(join(target, entry)); +} + +async function packageXmlFiles(mpk: string): Promise { + const target = await mkdtemp(join(tmp, "xml-")); + await unzip(mpk, target); + const xml = (await readXml(join(target, "package.xml"))) as any; + const file = xml.package.modelerProject.files.file; + return (Array.isArray(file) ? file : [file]).map(f => f["@_path"]); +} + +function moduleStepParams(config: object): ModuleStepParams { + return { config } as unknown as ModuleStepParams; +} + +describe("addTestProjectWidgetsToMpk", () => { + it("adds the widget mpks to the module mpk and lists them in package.xml", async () => { + const mpk = join(tmp, "build", "DataWidgets.mpk"); + const widgets = join(tmp, "widgets"); + await mkdir(join(tmp, "build")); + await mkdir(widgets); + await createModuleMpk(mpk); + const gallery = await createWidgetMpk(join(widgets, "Gallery.mpk")); + await createWidgetMpk(join(widgets, "Tree Node.mpk")); + + await addTestProjectWidgetsToMpk(["Gallery.mpk", "Tree Node.mpk"])( + moduleStepParams({ output: { files: { modulePackage: mpk }, dirs: { widgets } } }) + ); + + assert.deepEqual(await listArchive(mpk), [ + "DataWidgets.mpr", + "package.xml", + "themesource/datawidgets/web/main.scss", + "widgets/Gallery.mpk", + "widgets/Tree Node.mpk" + ]); + assert.deepEqual(await packageXmlFiles(mpk), [ + "themesource/datawidgets/web/main.scss", + "widgets/Gallery.mpk", + "widgets/Tree Node.mpk" + ]); + assert.deepEqual(await readFromArchive(mpk, "widgets/Gallery.mpk"), gallery); + assert.deepEqual(readdirSync(join(tmp, "build")), ["DataWidgets.mpk"], "temp folder is removed"); + }); +}); + +describe("copyFilesToMpk", () => { + it("copies the files into the mpk and lists them in package.xml", async () => { + const pkg = join(tmp, "package"); + const mpk = join(pkg, "dist", "DataWidgets.mpk"); + await writeTree(pkg, { "src/javascriptsource/actions/Action.js": "action" }); + await mkdir(join(pkg, "dist")); + await createModuleMpk(mpk); + + await copyFilesToMpk( + [ + { + filePath: join("src", "javascriptsource", "actions", "Action.js"), + pkgPath: "javascriptsource/Action.js" + } + ], + "modelerProject" + )(moduleStepParams({ paths: { package: pkg, tmp: join(pkg, "tmp") }, output: { files: { mpk } } })); + + assert.deepEqual(await listArchive(mpk), [ + "DataWidgets.mpr", + "javascriptsource/Action.js", + "package.xml", + "themesource/datawidgets/web/main.scss" + ]); + assert.deepEqual(await packageXmlFiles(mpk), [ + "themesource/datawidgets/web/main.scss", + "javascriptsource/Action.js" + ]); + assert.equal(existsSync(join(pkg, "tmp", "copyfiles_tmp")), false, "temp folder is removed"); + }); +}); + +describe("includeReadmeOssIntoMpk", () => { + it("adds the READMEOSS file to the mpk in place", async () => { + const mpk = join(tmp, "dist", "DataWidgets.mpk"); + const readme = join(tmp, "DataWidgets__3.0.0__READMEOSS_2026-01-01.html"); + await mkdir(join(tmp, "dist")); + await createModuleMpk(mpk); + await writeFile(readme, ""); + + await includeReadmeOssIntoMpk(readme, mpk); + + assert.deepEqual(await listArchive(mpk), [ + "DataWidgets.mpr", + "DataWidgets__3.0.0__READMEOSS_2026-01-01.html", + "package.xml", + "themesource/datawidgets/web/main.scss" + ]); + assert.deepEqual(readdirSync(join(tmp, "dist")), ["DataWidgets.mpk"], "temp folder is removed"); + }); +}); diff --git a/automation/utils/src/__tests__/shell.spec.ts b/automation/utils/src/__tests__/shell.spec.ts index c2b75c45a3..7a4ac77d56 100644 --- a/automation/utils/src/__tests__/shell.spec.ts +++ b/automation/utils/src/__tests__/shell.spec.ts @@ -109,6 +109,28 @@ describe("zip and unzip", () => { assert.equal(await readFile(join(tmp, "unzipped", "widgets", "a.mpk"), "utf-8"), "a"); }); + it("handles spaces in the archive, directory and entry paths", async () => { + await writeTree(tmp, { "my content/sub dir/a file.txt": "a" }); + const archive = join(tmp, "my output", "out file.mpk"); + await mkdir(join(tmp, "my output")); + + await zip(join(tmp, "my content"), archive); + await unzip(archive, join(tmp, "my unzipped")); + + assert.equal(await readFile(join(tmp, "my unzipped", "sub dir", "a file.txt"), "utf-8"), "a"); + }); + + it("keeps binary content intact", async () => { + const bytes = Buffer.from(Array.from({ length: 256 }, (_, i) => i)); + await mkdir(join(tmp, "content")); + await writeFile(join(tmp, "content", "data.bin"), bytes); + + await zip(join(tmp, "content"), join(tmp, "out.zip")); + await unzip(join(tmp, "out.zip"), join(tmp, "unzipped")); + + assert.deepEqual(await readFile(join(tmp, "unzipped", "data.bin")), bytes); + }); + it("restores the working directory after zipping", async () => { await writeTree(tmp, { "content/a.txt": "a" }); const cwd = process.cwd(); From 3028ca398ccbc614d2bb7acf0eb38d9db4afc7ac Mon Sep 17 00:00:00 2001 From: Roman Vyakhirev Date: Sat, 14 Nov 2026 04:50:20 +0100 Subject: [PATCH 8/8] ci: run automation-utils tests on the release build runners --- .github/workflows/BuildJobs.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/BuildJobs.yml b/.github/workflows/BuildJobs.yml index 18dc12830e..f42a574d78 100644 --- a/.github/workflows/BuildJobs.yml +++ b/.github/workflows/BuildJobs.yml @@ -66,10 +66,10 @@ jobs: - name: Verify changelog entries run: pnpm run -w check-changelogs if: >- - ${{ github.event_name == 'pull_request' && github.event.pull_request.user.login != 'uicontent' }} + ${{ github.event_name == 'pull_request' && github.event.pull_request.user.login != 'uicontent' }} env: - BASE_SHA: ${{ github.event.pull_request.base.sha }} - HEAD_SHA: ${{ github.event.pull_request.head.sha }} + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} mxversion: name: Read versions file @@ -134,6 +134,10 @@ jobs: turbo-cache-${{ runner.os }}-${{ matrix.target }} - name: Install dependencies run: pnpm install + # Exercises the release scripts' file and zip helpers with the runner's own tooling + # (zip/unzip on Linux, PowerShell on Windows), so a break shows up before a release does. + - name: Test release scripts + run: pnpm --filter @mendix/automation-utils run test - name: Run ${{ matrix.target }} task run: pnpm run ${{ matrix.target }} --concurrency=1 ${{ env.since_flag }} env: