From e874ab4d9a471aa61569817f93f95bac1c2e22ac Mon Sep 17 00:00:00 2001 From: Camillo Bruni Date: Tue, 21 Oct 2025 11:22:36 +0200 Subject: [PATCH 1/5] add version check --- package.json | 17 +++++++++-------- tests/helper.mjs | 23 +++++++++++++++++++++++ tests/run-browser.mjs | 24 ++++++++++++++++++++++++ tests/run-shell.mjs | 23 +++++++++++++++++++++++ tests/server.mjs | 23 +++++++++++++++++++++++ tests/unit-tests.js | 23 +++++++++++++++++++++++ utils/compress.mjs | 24 ++++++++++++++++++++++++ 7 files changed, 149 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 7b348193..85e7a68f 100644 --- a/package.json +++ b/package.json @@ -15,14 +15,15 @@ }, "license": "SEE LICENSE IN LICENSE", "scripts": { - "server": "node tests/server.mjs", - "compress": "node utils/compress.mjs", - "decompress": "node utils/compress.mjs --decompress --keep ", - "lint:check": "eslint **/*.{js,mjs,jsx,ts,tsx}", - "pretty:check": "prettier --check ./", - "pretty:format": "prettier --write ./", - "format:check": "npm run pretty:check && npm run lint:check", - "test:prepare": "npm run decompress -- --quiet", + "prepare": "node utils/version-check.mjs", + "server": "npm run prepare --silent && node tests/server.mjs", + "compress": "npm run prepare --silent && node utils/compress.mjs", + "decompress": "npm run prepare --silent && node utils/compress.mjs --decompress --keep ", + "lint:check": "npm run prepare --silent && eslint **/*.{js,mjs,jsx,ts,tsx}", + "pretty:check": "npm run prepare --silent && prettier --check ./", + "pretty:format": "npm run prepare --silent && prettier --write ./", + "format:check": "npm run prepare --silent && npm run pretty:check && npm run lint:check", + "test:prepare": "npm run prepare --silent && npm run decompress -- --quiet", "test:chrome": "npm run test:prepare && node tests/run-browser.mjs --browser chrome", "test:firefox": "npm run test:prepare && node tests/run-browser.mjs --browser firefox", "test:safari": "npm run test:prepare && node tests/run-browser.mjs --browser safari", diff --git a/tests/helper.mjs b/tests/helper.mjs index 0867e8a2..9dcd6d26 100644 --- a/tests/helper.mjs +++ b/tests/helper.mjs @@ -1,3 +1,26 @@ +// Copyright (C) 2007-2025 Apple Inc. All rights reserved. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. + +// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS +// BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +// THE POSSIBILITY OF SUCH DAMAGE. + import { styleText } from "node:util"; import core from "@actions/core"; import commandLineUsage from "command-line-usage"; diff --git a/tests/run-browser.mjs b/tests/run-browser.mjs index 52cf1235..7efaea69 100644 --- a/tests/run-browser.mjs +++ b/tests/run-browser.mjs @@ -1,5 +1,29 @@ #! /usr/bin/env node /* eslint-disable-next-line no-unused-vars */ + +// Copyright (C) 2007-2025 Apple Inc. All rights reserved. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. + +// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS +// BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +// THE POSSIBILITY OF SUCH DAMAGE. + import serve from "./server.mjs"; import { Builder, Capabilities } from "selenium-webdriver"; import commandLineArgs from "command-line-args"; diff --git a/tests/run-shell.mjs b/tests/run-shell.mjs index f20112c7..3a4c4972 100644 --- a/tests/run-shell.mjs +++ b/tests/run-shell.mjs @@ -1,5 +1,28 @@ #! /usr/bin/env node +// Copyright (C) 2007-2025 Apple Inc. All rights reserved. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. + +// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS +// BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +// THE POSSIBILITY OF SUCH DAMAGE. + import commandLineArgs from "command-line-args"; import { spawn } from "child_process"; import { fileURLToPath } from "url"; diff --git a/tests/server.mjs b/tests/server.mjs index c3444993..0b86ac96 100644 --- a/tests/server.mjs +++ b/tests/server.mjs @@ -1,3 +1,26 @@ +// Copyright (C) 2007-2025 Apple Inc. All rights reserved. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. + +// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS +// BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +// THE POSSIBILITY OF SUCH DAMAGE. + // Simple local server import * as path from "path"; import commandLineArgs from "command-line-args"; diff --git a/tests/unit-tests.js b/tests/unit-tests.js index 507be43e..3bc3c3e4 100644 --- a/tests/unit-tests.js +++ b/tests/unit-tests.js @@ -1,3 +1,26 @@ +// Copyright (C) 2007-2025 Apple Inc. All rights reserved. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. + +// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS +// BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +// THE POSSIBILITY OF SUCH DAMAGE. + load("shell-config.js"); load("params.js"); load("startup-helper/StartupBenchmark.js"); diff --git a/utils/compress.mjs b/utils/compress.mjs index 4e5c5cc6..b47e5fe7 100644 --- a/utils/compress.mjs +++ b/utils/compress.mjs @@ -1,3 +1,27 @@ +// Copyright (C) 2007-2025 Apple Inc. All rights reserved. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. + +// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS +// BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +// THE POSSIBILITY OF SUCH DAMAGE. + + import commandLineArgs from 'command-line-args'; import commandLineUsage from 'command-line-usage'; import { globSync } from 'glob'; From 770491242486370950e8052c1e6bc9260ab9d81c Mon Sep 17 00:00:00 2001 From: Camillo Bruni Date: Tue, 21 Oct 2025 11:22:54 +0200 Subject: [PATCH 2/5] add file --- utils/version-check.mjs | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 utils/version-check.mjs diff --git a/utils/version-check.mjs b/utils/version-check.mjs new file mode 100644 index 00000000..84eefb0e --- /dev/null +++ b/utils/version-check.mjs @@ -0,0 +1,45 @@ +// Copyright (C) 2025 Google LLC + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. + +// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS +// BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +// THE POSSIBILITY OF SUCH DAMAGE. + + +import fs from "node:fs/promises"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; + +const dirname = path.dirname(fileURLToPath(import.meta.url)); +const projectRoot = path.join(dirname, ".."); +const packageJsonPath = path.join(projectRoot, "package.json"); + +const packageJsonContent = await fs.readFile(packageJsonPath, "utf8"); +const pkg = JSON.parse(packageJsonContent); + +const nodeEngine = pkg.engines?.node; +// Regex to parse simple ">= MAJOR[.MINOR[.PATCH]]" +const match = nodeEngine.match(/>=?\s*(\d+)(\.\d+)?(\.\d+)?/); +const requiredMajor = parseInt(match[1]); +const currentMajor = parseInt(process.versions.node.split(".")[0]); + +if (currentMajor < requiredMajor) { + console.error(`❌ Error: Node.js v${requiredMajor} or higher require. expected: "${nodeEngine}", current: ${process.version}).`; + process.exit(1); +} \ No newline at end of file From 4ef2cf9c2b04d46d7fbd6d9134271d31efd7e264 Mon Sep 17 00:00:00 2001 From: Camillo Bruni Date: Tue, 21 Oct 2025 11:23:31 +0200 Subject: [PATCH 3/5] fix --- utils/version-check.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/version-check.mjs b/utils/version-check.mjs index 84eefb0e..8b81cbf8 100644 --- a/utils/version-check.mjs +++ b/utils/version-check.mjs @@ -40,6 +40,6 @@ const requiredMajor = parseInt(match[1]); const currentMajor = parseInt(process.versions.node.split(".")[0]); if (currentMajor < requiredMajor) { - console.error(`❌ Error: Node.js v${requiredMajor} or higher require. expected: "${nodeEngine}", current: ${process.version}).`; + console.error(`❌ Error: Node.js v${requiredMajor} or higher require. expected: "${nodeEngine}", current: ${process.version}).`); process.exit(1); } \ No newline at end of file From 785d91808a29f08c6f1f7d33c25a6187ed528a67 Mon Sep 17 00:00:00 2001 From: Camillo Bruni Date: Tue, 21 Oct 2025 11:31:16 +0200 Subject: [PATCH 4/5] formatting --- utils/version-check.mjs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/utils/version-check.mjs b/utils/version-check.mjs index 8b81cbf8..d53cddb3 100644 --- a/utils/version-check.mjs +++ b/utils/version-check.mjs @@ -21,7 +21,6 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF // THE POSSIBILITY OF SUCH DAMAGE. - import fs from "node:fs/promises"; import path from "node:path"; import { fileURLToPath } from "node:url"; @@ -40,6 +39,8 @@ const requiredMajor = parseInt(match[1]); const currentMajor = parseInt(process.versions.node.split(".")[0]); if (currentMajor < requiredMajor) { - console.error(`❌ Error: Node.js v${requiredMajor} or higher require. expected: "${nodeEngine}", current: ${process.version}).`); - process.exit(1); -} \ No newline at end of file + console.error( + `❌ Error: Node.js v${requiredMajor} or higher require. expected: "${nodeEngine}", current: ${process.version}).` + ); + process.exit(1); +} From 22e0ea706248b6918ceb7acfc32da44ccc7de104 Mon Sep 17 00:00:00 2001 From: Camillo Bruni Date: Wed, 22 Oct 2025 16:38:20 +0200 Subject: [PATCH 5/5] update header --- utils/version-check.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/version-check.mjs b/utils/version-check.mjs index d53cddb3..24aa28e0 100644 --- a/utils/version-check.mjs +++ b/utils/version-check.mjs @@ -1,3 +1,4 @@ +// Copyright (C) 2007-2025 Apple Inc. All rights reserved. // Copyright (C) 2025 Google LLC // Redistribution and use in source and binary forms, with or without