diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e0024eff3..c65e09c48 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,25 +5,58 @@ on: pull_request: branches: [master] jobs: + build: + runs-on: ubuntu-latest + name: Build on Node.js 22 + steps: + - name: Setup Node.js 22 + uses: actions/setup-node@v4 + with: + node-version: 22 + - name: Checkout repository + uses: actions/checkout@v4 + - name: Install dependencies + run: npm install + - name: Build + run: npm run build + - name: Lint + run: npm run lint + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: build-artifacts + path: | + index.js + lib/ + es/ + validator.js + validator.min.js + retention-days: 1 + test: + needs: build runs-on: ubuntu-latest strategy: matrix: node-version: [22, 20, 18, 16, 14, 12, 10, 8] name: Run tests on Node.js ${{ matrix.node-version }} steps: - - name: Setup Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node-version }} - - name: Checkout repository - uses: actions/checkout@v4 - - name: Install dependencies - run: npm install --legacy-peer-deps - - name: Run tests - run: npm test - - if: matrix.node-version == 22 - name: Send coverage info to Codecov - uses: codecov/codecov-action@v5 - with: - token: ${{ secrets.CODECOV_TOKEN }} + - name: Setup Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + - name: Checkout repository + uses: actions/checkout@v4 + - name: Download build artifacts + uses: actions/download-artifact@v4 + with: + name: build-artifacts + - name: Install dependencies + run: npm install + - name: Run tests + run: npm run test:ci + - if: matrix.node-version == 22 + name: Send coverage info to Codecov + uses: codecov/codecov-action@v5 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 008a86ce6..672997bc5 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -17,7 +17,7 @@ jobs: - name: Checkout Repository uses: actions/checkout@v4 - name: Install Dependencies - run: npm install --legacy-peer-deps + run: npm install - name: Run Tests run: npm test - name: Publish Package to NPM Registry diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 747a30ea2..a1f861379 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,7 +8,7 @@ In general, we follow the "fork-and-pull" Git workflow. 1. [Fork](https://docs.github.com/en/get-started/exploring-projects-on-github/contributing-to-a-project) the repository on GitHub 2. Clone the project to your local machine 3. Work on your fork - * Install the project using `npm install --legacy-peer-deps` (see [issue](https://github.com/validatorjs/validator.js/issues/2123)) + * Install the project using `npm install` * Make your changes and additions - Most of your changes should be focused on src/ and test/ folders and/or [README.md](https://github.com/validatorjs/validator.js/blob/master/README.md). - Files such as validator.js, validator.min.js and files in lib/ folder are autogenerated when running tests (npm test) and need not to be changed **manually**. diff --git a/build-browser.js b/build-browser.js deleted file mode 100644 index c863bd399..000000000 --- a/build-browser.js +++ /dev/null @@ -1,32 +0,0 @@ -/* eslint import/no-extraneous-dependencies: 0 */ -import fs from "fs"; -import { rollup } from "rollup"; -import babel from "rollup-plugin-babel"; -import babelPresetEnv from "@babel/preset-env"; -import pkg from "./package.json"; - -rollup({ - entry: "src/index.js", - plugins: [ - babel({ - presets: [[babelPresetEnv, { modules: false }]], - babelrc: false, - }), - ], -}) - .then((bundle) => - bundle.write({ - dest: "validator.js", - format: "umd", - moduleName: pkg.name, - banner: `/*!\n${String(fs.readFileSync("./LICENSE")) - .trim() - .split("\n") - .map((l) => ` * ${l}`) - .join("\n")}\n */`, - }) - ) - .catch((e) => { - process.stderr.write(`${e.message}\n`); - process.exit(1); - }); diff --git a/build-browser.mjs b/build-browser.mjs new file mode 100644 index 000000000..b770acb94 --- /dev/null +++ b/build-browser.mjs @@ -0,0 +1,39 @@ +/* eslint import/no-extraneous-dependencies: 0 */ +import fs from 'fs'; +import { rollup } from 'rollup'; +import { babel } from '@rollup/plugin-babel'; +import babelPresetEnv from '@babel/preset-env'; +import pkg from "./package.json" with { type: "json" }; + +rollup({ + input: 'src/index.js', + plugins: [ + babel({ + presets: [[babelPresetEnv, { + modules: false, + targets: { + node: '0.10', + ie: '11' + } + }]], + babelHelpers: 'bundled', + babelrc: false, + }), + ], +}) + .then((bundle) => + bundle.write({ + file: 'validator.js', + format: 'umd', + name: pkg.name, + banner: `/*!\n${String(fs.readFileSync('./LICENSE')) + .trim() + .split('\n') + .map((l) => ` * ${l}`) + .join('\n')}\n */`, + }) + ) + .catch((e) => { + process.stderr.write(`${e.message}\n`); + process.exit(1); + }); diff --git a/package.json b/package.json index aa019c56b..e31b413c6 100644 --- a/package.json +++ b/package.json @@ -36,10 +36,11 @@ "url": "git+https://github.com/validatorjs/validator.js.git" }, "devDependencies": { - "@babel/cli": "^7.0.0", - "@babel/core": "^7.0.0", - "@babel/preset-env": "^7.0.0", - "@babel/register": "^7.0.0", + "@babel/cli": "^7.28.3", + "@babel/core": "^7.28.5", + "@babel/preset-env": "^7.28.5", + "@babel/register": "^7.28.3", + "@rollup/plugin-babel": "^6.1.0", "babel-eslint": "^10.0.1", "babel-plugin-add-module-exports": "^1.0.0", "eslint": "^4.19.1", @@ -49,8 +50,7 @@ "npm-run-all": "^4.1.5", "nyc": "^14.1.0", "rimraf": "^3.0.0", - "rollup": "^0.47.0", - "rollup-plugin-babel": "^4.0.1", + "rollup": "^4.53.2", "timezone-mock": "^1.3.6", "uglify-js": "^3.0.19" }, @@ -62,12 +62,13 @@ "clean:browser": "rimraf validator*.js", "clean": "run-p clean:*", "minify": "uglifyjs validator.js -o validator.min.js --compress --mangle --comments /Copyright/", - "build:browser": "node --require @babel/register build-browser && npm run minify", + "build:browser": "node build-browser.mjs && npm run minify", "build:es": "babel src -d es --env-name=es", "build:node": "babel src -d .", "build": "run-p build:*", "pretest": "npm run build && npm run lint", - "test": "nyc --reporter=cobertura --reporter=text-summary mocha --require @babel/register --reporter dot --recursive" + "test": "npm run test:ci", + "test:ci": "nyc --reporter=cobertura --reporter=text-summary mocha --require @babel/register --reporter dot --recursive" }, "engines": { "node": ">= 0.10"