From e8d2e34339078ece6ce2bef13243e75e134749ab Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Fri, 16 Apr 2021 11:16:09 -0700 Subject: [PATCH 1/3] Build: Update scripts for release (fixes #475) --- lib/version.js | 2 +- package.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/version.js b/lib/version.js index 4f278043..7176acb0 100644 --- a/lib/version.js +++ b/lib/version.js @@ -1,3 +1,3 @@ -const version = "7.3.1"; +const version = "main"; export default version; diff --git a/package.json b/package.json index 698c9cd6..4e1c5e57 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,8 @@ "test": "npm-run-all -p unit lint", "lint": "eslint \"*.?(c)js\" lib/ tests/lib/", "fixlint": "npm run lint -- --fix", - "rollup": "rollup -c rollup.config.js", + "build": "rollup -c rollup.config.js", + "prepare": "npm run build", "sync-docs": "node sync-docs.js", "generate-release": "eslint-generate-release", "generate-alpharelease": "eslint-generate-prerelease alpha", From 723c1306baa5ccac40a11dc2af696974b4f4f4f9 Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Fri, 16 Apr 2021 11:26:01 -0700 Subject: [PATCH 2/3] Update scripts --- package.json | 4 +++- rollup.config.js | 9 --------- tools/update-version.js | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 tools/update-version.js diff --git a/package.json b/package.json index 4e1c5e57..cf6efbdc 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,9 @@ "lint": "eslint \"*.?(c)js\" lib/ tests/lib/", "fixlint": "npm run lint -- --fix", "build": "rollup -c rollup.config.js", - "prepare": "npm run build", + "update-version": "node tools/update-version.js", + "pretest": "npm run build", + "prepublishOnly": "npm run update-version && npm run build", "sync-docs": "node sync-docs.js", "generate-release": "eslint-generate-release", "generate-alpharelease": "eslint-generate-prerelease alpha", diff --git a/rollup.config.js b/rollup.config.js index 183e15a5..384bf143 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,15 +1,6 @@ import commonjs from "@rollup/plugin-commonjs"; import resolve from "@rollup/plugin-node-resolve"; import json from "@rollup/plugin-json"; -import fs from "fs"; - - -// the espree package version is exported from the module (i.e., import { version } from "espree") -// read version from the package.json metadata and write it into lib/version.js at build time, -// since esm cannot import json by default -const pkg = JSON.parse(fs.readFileSync("./package.json", "utf8")); - -fs.writeFileSync("lib/version.js", `const version = "${pkg.version}";\n\nexport default version;\n`); export default { input: "espree.js", diff --git a/tools/update-version.js b/tools/update-version.js new file mode 100644 index 00000000..052c561d --- /dev/null +++ b/tools/update-version.js @@ -0,0 +1,17 @@ +/** + * @fileoverview Script to update lib/version.js to the value in package.json + * @author Nicholas C. Zakas + */ + +import fs from "fs"; + +/* + * IMPORTANT: This must be run *before* Rollup so the built package will have + * the correct version number exported. + * + * This is necessary because ESM can't import JSON files directly and we want + * this value to be available in the browser as well as in Node.js. + */ + +const pkg = JSON.parse(fs.readFileSync("./package.json", "utf8")); +fs.writeFileSync("lib/version.js", `const version = "${pkg.version}";\n\nexport default version;\n`); From 9d7abf5dd2232f85fb3e207260d4919b69db1c91 Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Mon, 19 Apr 2021 10:03:35 -0700 Subject: [PATCH 3/3] Update CI script --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d7e871fc..a84b6ab4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: - name: Install dependencies run: npm install - name: Build commonjs - run: npm run rollup + run: npm run build - name: Lint files run: npm run lint test: @@ -46,7 +46,7 @@ jobs: run: npm install --legacy-peer-deps if: ${{ startswith(matrix.node, '15') }} - name: Build commonjs - run: npm run rollup + run: npm run build - name: Run tests run: npm run unit testNode10: @@ -64,6 +64,6 @@ jobs: - name: Install dependencies run: npm install - name: Build commonjs - run: npm run rollup + run: npm run build - name: Run tests run: npm run unit:cjs