Skip to content

Commit

Permalink
Build: Update scripts for release (fixes #475) (#478)
Browse files Browse the repository at this point in the history
* Build: Update scripts for release (fixes #475)

* Update scripts

* Update CI script
  • Loading branch information
nzakas committed Apr 19, 2021
1 parent 5dd3dee commit 8209e4e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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
2 changes: 1 addition & 1 deletion lib/version.js
@@ -1,3 +1,3 @@
const version = "7.3.1";
const version = "main";

export default version;
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -74,7 +74,10 @@
"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",
"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",
Expand Down
9 changes: 0 additions & 9 deletions 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",
Expand Down
17 changes: 17 additions & 0 deletions 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`);

0 comments on commit 8209e4e

Please sign in to comment.