From 7fd86d694d3dc23b20b45d8d43118d2f554392aa Mon Sep 17 00:00:00 2001 From: spalger Date: Fri, 13 Mar 2020 09:18:14 -0700 Subject: [PATCH] Revert "Using re2 for Timelion regular expressions (#55208) (#60055)" This reverts commit 2610d49aa8d1d202e44c59927ead5255dd5efab6. --- .gitignore | 1 - package.json | 1 - src/dev/build/build_distributables.js | 2 - src/dev/build/lib/index.js | 1 - src/dev/build/tasks/index.js | 1 - .../nodejs}/__tests__/download.js | 0 .../__tests__/download_node_builds_task.js | 2 +- .../build/{lib => tasks/nodejs}/download.js | 2 +- .../tasks/nodejs/download_node_builds_task.js | 2 +- .../build/tasks/patch_native_modules_task.js | 85 ------------------- .../timelion/server/series_functions/label.js | 5 +- yarn.lock | 9 +- 12 files changed, 5 insertions(+), 106 deletions(-) rename src/dev/build/{lib => tasks/nodejs}/__tests__/download.js (100%) rename src/dev/build/{lib => tasks/nodejs}/download.js (98%) delete mode 100644 src/dev/build/tasks/patch_native_modules_task.js diff --git a/.gitignore b/.gitignore index 97b6f9a45eeab..f435a448406e5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ /.es .DS_Store .node_binaries -.native_modules node_modules !/src/dev/npm/integration_tests/__fixtures__/fixture1/node_modules !/src/dev/notice/__fixtures__/node_modules diff --git a/package.json b/package.json index d4f19eecc7527..ad9ba85fd8eb8 100644 --- a/package.json +++ b/package.json @@ -225,7 +225,6 @@ "pug": "^2.0.4", "query-string": "6.10.1", "raw-loader": "3.1.0", - "re2": "1.10.5", "react": "^16.12.0", "react-color": "^2.13.8", "react-dom": "^16.12.0", diff --git a/src/dev/build/build_distributables.js b/src/dev/build/build_distributables.js index 008281db8bb93..6c2efeebc60c3 100644 --- a/src/dev/build/build_distributables.js +++ b/src/dev/build/build_distributables.js @@ -45,7 +45,6 @@ import { InstallDependenciesTask, BuildKibanaPlatformPluginsTask, OptimizeBuildTask, - PatchNativeModulesTask, RemovePackageJsonDepsTask, RemoveWorkspacesTask, TranspileBabelTask, @@ -133,7 +132,6 @@ export async function buildDistributables(options) { * directories and perform platform-specific steps */ await run(CreateArchivesSourcesTask); - await run(PatchNativeModulesTask); await run(CleanExtraBinScriptsTask); await run(CleanExtraBrowsersTask); await run(CleanNodeBuildsTask); diff --git a/src/dev/build/lib/index.js b/src/dev/build/lib/index.js index 25c4b74eefd22..afebd090d797d 100644 --- a/src/dev/build/lib/index.js +++ b/src/dev/build/lib/index.js @@ -33,6 +33,5 @@ export { compress, isFileAccessible, } from './fs'; -export { download } from './download'; export { scanDelete } from './scan_delete'; export { scanCopy } from './scan_copy'; diff --git a/src/dev/build/tasks/index.js b/src/dev/build/tasks/index.js index 1faae655c9abb..8105fa8a7d5d4 100644 --- a/src/dev/build/tasks/index.js +++ b/src/dev/build/tasks/index.js @@ -32,7 +32,6 @@ export * from './nodejs_modules'; export * from './notice_file_task'; export * from './optimize_task'; export * from './os_packages'; -export * from './patch_native_modules_task'; export * from './transpile_babel_task'; export * from './transpile_scss_task'; export * from './verify_env_task'; diff --git a/src/dev/build/lib/__tests__/download.js b/src/dev/build/tasks/nodejs/__tests__/download.js similarity index 100% rename from src/dev/build/lib/__tests__/download.js rename to src/dev/build/tasks/nodejs/__tests__/download.js diff --git a/src/dev/build/tasks/nodejs/__tests__/download_node_builds_task.js b/src/dev/build/tasks/nodejs/__tests__/download_node_builds_task.js index 1048a8c7386bc..4c94ed776417d 100644 --- a/src/dev/build/tasks/nodejs/__tests__/download_node_builds_task.js +++ b/src/dev/build/tasks/nodejs/__tests__/download_node_builds_task.js @@ -22,7 +22,7 @@ import expect from '@kbn/expect'; import * as NodeShasumsNS from '../node_shasums'; import * as NodeDownloadInfoNS from '../node_download_info'; -import * as DownloadNS from '../../../lib/download'; // sinon can't stub '../../../lib' properly +import * as DownloadNS from '../download'; import { DownloadNodeBuildsTask } from '../download_node_builds_task'; describe('src/dev/build/tasks/nodejs/download_node_builds_task', () => { diff --git a/src/dev/build/lib/download.js b/src/dev/build/tasks/nodejs/download.js similarity index 98% rename from src/dev/build/lib/download.js rename to src/dev/build/tasks/nodejs/download.js index 97f82ed14b409..0bd10e5b84015 100644 --- a/src/dev/build/lib/download.js +++ b/src/dev/build/tasks/nodejs/download.js @@ -24,7 +24,7 @@ import chalk from 'chalk'; import { createHash } from 'crypto'; import Axios from 'axios'; -import { mkdirp } from './fs'; +import { mkdirp } from '../../lib'; function tryUnlink(path) { try { diff --git a/src/dev/build/tasks/nodejs/download_node_builds_task.js b/src/dev/build/tasks/nodejs/download_node_builds_task.js index 12e9245262c56..df841960677c1 100644 --- a/src/dev/build/tasks/nodejs/download_node_builds_task.js +++ b/src/dev/build/tasks/nodejs/download_node_builds_task.js @@ -17,7 +17,7 @@ * under the License. */ -import { download } from '../../lib'; +import { download } from './download'; import { getNodeShasums } from './node_shasums'; import { getNodeDownloadInfo } from './node_download_info'; diff --git a/src/dev/build/tasks/patch_native_modules_task.js b/src/dev/build/tasks/patch_native_modules_task.js deleted file mode 100644 index 28fc9ebf3d61f..0000000000000 --- a/src/dev/build/tasks/patch_native_modules_task.js +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -import fs from 'fs'; -import path from 'path'; -import util from 'util'; -import { deleteAll, download, untar } from '../lib'; - -const BASE_URL = `https://storage.googleapis.com/native-modules`; -const DOWNLOAD_DIRECTORY = '.native_modules'; - -const packages = [ - { - name: 're2', - version: '1.10.5', - destinationPath: 'node_modules/re2/build/Release/', - shas: { - darwin: '066533b592094f91e00412499e44c338ce2466d63c9eaf0dc32be8214bde2099', - linux: '0322cac3c2e106129b650a8eac509f598ed283791d6116984fec4c151b24e574', - windows: '65b5bef7de2352f4787224c2c76a619b6683a868c8d4d71e0fdd500786fc422b', - }, - }, -]; - -async function getInstalledVersion(config, packageName) { - const packageJSONPath = config.resolveFromRepo( - path.join('node_modules', packageName, 'package.json') - ); - const buffer = await util.promisify(fs.readFile)(packageJSONPath); - const packageJSON = JSON.parse(buffer); - return packageJSON.version; -} - -async function patchModule(config, log, build, platform, pkg) { - const installedVersion = await getInstalledVersion(config, pkg.name); - if (installedVersion !== pkg.version) { - throw new Error( - `Can't patch ${pkg.name}'s native module, we were expecting version ${pkg.version} and found ${installedVersion}` - ); - } - const platformName = platform.getName(); - const archiveName = `${pkg.version}-${platformName}.tar.gz`; - const downloadUrl = `${BASE_URL}/${pkg.name}/${archiveName}`; - const downloadPath = config.resolveFromRepo(DOWNLOAD_DIRECTORY, archiveName); - const extractedPath = build.resolvePathForPlatform(platform, pkg.destinationPath); - log.debug(`Patching ${pkg.name} binaries from ${downloadUrl} to ${extractedPath}`); - - await deleteAll([extractedPath], log); - await download({ - log, - url: downloadUrl, - destination: downloadPath, - sha256: pkg.shas[platformName], - retries: 3, - }); - await untar(downloadPath, extractedPath); -} - -export const PatchNativeModulesTask = { - description: 'Patching platform-specific native modules', - async run(config, log, build) { - for (const pkg of packages) { - await Promise.all( - config.getTargetPlatforms().map(async platform => { - await patchModule(config, log, build, platform, pkg); - }) - ); - } - }, -}; diff --git a/src/plugins/timelion/server/series_functions/label.js b/src/plugins/timelion/server/series_functions/label.js index 6e46a92b48add..1e4782e5a381e 100644 --- a/src/plugins/timelion/server/series_functions/label.js +++ b/src/plugins/timelion/server/series_functions/label.js @@ -51,10 +51,7 @@ export default new Chainable('label', { const config = args.byName; return alter(args, function(eachSeries) { if (config.regex) { - // not using a standard `import` so that if there's an issue with the re2 native module - // that it doesn't prevent Kibana from starting up and we only have an issue using Timelion labels - const RE2 = require('re2'); - eachSeries.label = eachSeries.label.replace(new RE2(config.regex), config.label); + eachSeries.label = eachSeries.label.replace(new RegExp(config.regex), config.label); } else { eachSeries.label = config.label; } diff --git a/yarn.lock b/yarn.lock index 412c2f9fb2a6a..20e58cd37d5a3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -21835,7 +21835,7 @@ mute-stream@0.0.8: resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d" integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA== -nan@^2.13.2, nan@^2.14.0, nan@^2.9.2: +nan@^2.13.2, nan@^2.9.2: version "2.14.0" resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.0.tgz#7818f722027b2459a86f0295d434d1fc2336c52c" integrity sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg== @@ -24872,13 +24872,6 @@ re-resizable@^6.1.1: dependencies: fast-memoize "^2.5.1" -re2@1.10.5: - version "1.10.5" - resolved "https://registry.yarnpkg.com/re2/-/re2-1.10.5.tgz#b3730438121c6bf59d459aff3471177eef513445" - integrity sha512-ssO3AD8/YJzuQUgEasS8PxA8n1yg8JB2VNSJhCebuuHLwaGiufhtFGUypS2bONrCPDbjwlMy7OZD9LkcrQMr1g== - dependencies: - nan "^2.14.0" - react-ace@^5.5.0: version "5.10.0" resolved "https://registry.yarnpkg.com/react-ace/-/react-ace-5.10.0.tgz#e328b37ac52759f700be5afdb86ada2f5ec84c5e"