blob: 06dca8c413dec203a1d667466b9408aed332aa5b [file] [log] [blame]
Jack Franklinb5a63092022-11-30 14:32:361#!/usr/bin/env node
2
3// Copyright 2022 The Chromium Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6'use strict';
7
8const path = require('path');
9const fs = require('fs');
10
11const {
12 devtoolsRootPath,
13} = require('./devtools_paths.js');
14
15function bail(message) {
16 console.error(message);
17 process.exit(1);
18}
19
20function findVersionFromDepsFile() {
21 const filePath = path.join(devtoolsRootPath(), 'DEPS');
22 const contents = fs.readFileSync(filePath, 'utf8').split('\n');
23 const esbuildPackageLine = contents.findIndex(line => line.match(/infra\/3pp\/tools\/esbuild/));
24 if (esbuildPackageLine === -1) {
25 bail('Could not find ESBuild within DEPS file.');
26 }
27 const esbuildVersionLine = contents[esbuildPackageLine + 1];
28 const result = /@(\d{1,2}\.\d{1,2}\.\d{1,2})/.exec(esbuildVersionLine)?.[1];
29 if (!result) {
30 bail('Could not parse out ESBuild version from DEPS');
31 }
32 return result;
33}
34
Alex Rudenko2e05f8f2024-04-04 10:36:5935function findVersionFromPackageJsonFile() {
36 const filePath = path.join(devtoolsRootPath(), 'package.json');
Jack Franklinb5a63092022-11-30 14:32:3637 const contents = fs.readFileSync(filePath, 'utf8');
38 const result = /"esbuild": "([0-9\.]+)"/.exec(contents)?.[1];
39 if (!result) {
Alex Rudenko2e05f8f2024-04-04 10:36:5940 bail('Could not parse out ESBuild version from package.json');
Jack Franklinb5a63092022-11-30 14:32:3641 }
42 return result;
43}
44
Alex Rudenko2e05f8f2024-04-04 10:36:5945const nodeDepsVersion = findVersionFromPackageJsonFile();
Jack Franklinb5a63092022-11-30 14:32:3646const depsVersion = findVersionFromDepsFile();
47if (nodeDepsVersion !== depsVersion) {
Alex Rudenko2e05f8f2024-04-04 10:36:5948 bail(`Found mismatching esbuild versions in DEPS vs package.json:
49 package.json: ${nodeDepsVersion}
50 DEPS: ${depsVersion}\n`);
Jack Franklinb5a63092022-11-30 14:32:3651}