From bd9e935891e0dfc8b3079d3d02d741954999bcb9 Mon Sep 17 00:00:00 2001 From: nickofthyme Date: Wed, 19 May 2021 20:42:59 -0500 Subject: [PATCH 01/10] build: enable linking charts library to kibana --- .eslintrc.js | 6 + package.json | 8 +- .../eslint-plugin-elastic-charts/package.json | 1 + packages/link_kibana/index.js | 22 + packages/link_kibana/main.js | 234 ++++++++ packages/link_kibana/package.json | 14 + packages/link_kibana/process_utils.js | 152 +++++ packages/link_kibana/replace_modules.js | 87 +++ packages/link_kibana/utils.js | 166 ++++++ packages/link_kibana/yarn.lock | 540 ++++++++++++++++++ tsconfig.lib-nocomments.json | 4 +- tsconfig.lib.json | 2 +- yarn.lock | 9 +- 13 files changed, 1236 insertions(+), 9 deletions(-) create mode 100644 packages/link_kibana/index.js create mode 100644 packages/link_kibana/main.js create mode 100644 packages/link_kibana/package.json create mode 100644 packages/link_kibana/process_utils.js create mode 100644 packages/link_kibana/replace_modules.js create mode 100644 packages/link_kibana/utils.js create mode 100644 packages/link_kibana/yarn.lock diff --git a/.eslintrc.js b/.eslintrc.js index 8f22a683ea..d3ac7ded69 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -468,5 +468,11 @@ module.exports = { ], }, }, + { + files: ['packages/link_kibana/**/*.js'], + rules: { + 'no-console': 0, + }, + }, ], }; diff --git a/package.json b/package.json index 1c262fd002..4e0347189d 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "build:compile": "echo 'Compiling...' && tsc -p ./tsconfig.lib.json && tsc -p ./tsconfig.lib-nocomments.json", "build:sass": "echo 'Building sass...' && node-sass src/theme_light.scss dist/theme_light.css --output-style compressed && node-sass src/theme_dark.scss dist/theme_dark.css --output-style compressed && node-sass src/theme_only_light.scss dist/theme_only_light.css --output-style compressed && node-sass src/theme_only_dark.scss dist/theme_only_dark.css --output-style compressed", "build:check": "echo 'Type checking dist...' && tsc -p ./tsconfig.lib-check.json", - "build:watch": "echo 'Watching build...' && yarn build:clean && yarn build:css && yarn build:compile -w ", + "build:watch": "echo 'Watching build...' && yarn build:clean && yarn build:css && tsc -p ./tsconfig.lib.json -w", "concat:sass": "echo 'Concat SASS...' && node scripts/concat_sass.js", "cz": "git-cz", "lint": "NODE_ENV=production eslint --quiet --ext .tsx,.ts,.js .", @@ -59,8 +59,7 @@ "typecheck:all": "tsc -p ./tsconfig.json --noEmit", "ts:prune": "ts-prune", "watch": "yarn test --watch", - "index:check": "ts-node scripts/index_check.ts", - "tsdocs:check": "ts-node scripts/tsdoc_check.ts" + "link:kibana": "node ./packages/link_kibana" }, "dependencies": { "@popperjs/core": "^2.4.0", @@ -157,7 +156,7 @@ "eslint": "^7.17.0", "eslint-config-airbnb-typescript": "^12.0.0", "eslint-config-prettier": "^7.1.0", - "eslint-plugin-elastic-charts": "file:./packages/eslint-plugin-elastic-charts", + "eslint-plugin-elastic-charts": "link:./packages/eslint-plugin-elastic-charts", "eslint-plugin-eslint-comments": "^3.2.0", "eslint-plugin-file-header": "^0.0.1", "eslint-plugin-header": "^3.1.0", @@ -177,6 +176,7 @@ "jest-matcher-utils": "^26.6.2", "jest-puppeteer": "^4.4.0", "jest-puppeteer-docker": "^1.4.2", + "link-kibana": "link:./packages/link_kibana", "lint-staged": "^10.5.3", "lodash": "^4.17.15", "lorem-ipsum": "^2.0.3", diff --git a/packages/eslint-plugin-elastic-charts/package.json b/packages/eslint-plugin-elastic-charts/package.json index 87986c3e55..a05ae545f1 100644 --- a/packages/eslint-plugin-elastic-charts/package.json +++ b/packages/eslint-plugin-elastic-charts/package.json @@ -1,6 +1,7 @@ { "name": "eslint-plugin-elastic-charts", "description": "Custom elastic-charts lint plugin", + "license": "Apache-2.0", "version": "1.0.0", "main": "index.js" } diff --git a/packages/link_kibana/index.js b/packages/link_kibana/index.js new file mode 100644 index 0000000000..d8ae63391b --- /dev/null +++ b/packages/link_kibana/index.js @@ -0,0 +1,22 @@ +/* + * 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. + */ + +const main = require('./main'); + +void main(); diff --git a/packages/link_kibana/main.js b/packages/link_kibana/main.js new file mode 100644 index 0000000000..642e47ec5a --- /dev/null +++ b/packages/link_kibana/main.js @@ -0,0 +1,234 @@ +/* + * 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. + */ + +const path = require('path'); + +const chalk = require('chalk'); +const inquirer = require('inquirer'); +const ora = require('ora'); + +const { spawnWatch, exec } = require('./process_utils'); +const { replaceModules } = require('./replace_modules'); +const { + getPackageInfo, + getTempDir, + getLinkInfo, + writeLinkInfo, + isLinked, + linkPackage, + unlinkPackage, +} = require('./utils'); + +/** + * This script is used to handling symlinking elastic charts to kibana. + * The cli walks you through the require parameters and runs the build + * in watch mode to facilitate the entire linking process. + * + * NOTE: This does **not** rebuild css files, only typescript files + */ +module.exports = async () => { + // child processes for cleanup + const cps = []; + const cleanExit = () => { + cps.forEach((cp) => cp && cp.kill()); + process.exit(); // eslint-disable-line unicorn/no-process-exit + }; + process.on('SIGINT', cleanExit); // catch ctrl-c + process.on('SIGTERM', cleanExit); // catch kill + + const echDir = process.cwd(); + const echPackageContent = await getPackageInfo(echDir); + const packageName = echPackageContent.name; + + if (packageName !== '@elastic/charts') { + if (packageName) throw new Error('This script is only designed for use with @elastic/charts'); + throw new Error('No name defined in package.json'); + } + + const tempDir = await getTempDir(echDir, packageName); + const linkInfo = await getLinkInfo(tempDir); + const linkedPackages = ['react', 'react-dom', 'redux', 'react-redux']; + + const { action } = await inquirer.prompt({ + name: 'action', + message: 'Select action', + type: 'list', + default: 'link', + choices: ['Link', 'Unlink', 'Watch mode'], + }); + + if (action === 'Link') { + const { appLinkRelativePath } = await inquirer.prompt({ + name: 'appLinkRelativePath', + message: 'Enter path to applitcation directory to link', + default: '../kibana', + }); + const kibanaPath = path.resolve(echDir, appLinkRelativePath); + const kibanaPackageInfo = await getPackageInfo(kibanaPath); + + if (kibanaPackageInfo.name !== 'kibana') { + console.log(` +Expected app name to be ${chalk.cyan('kibana')}, found ${chalk.cyan(kibanaPackageInfo.name)}. + +to link charts with another application use ${chalk.cyan( + 'yarn link', + )} (see https://classic.yarnpkg.com/en/docs/cli/link/) +`); + return; + } + + if (linkInfo.path) { + if (linkInfo.path !== kibanaPath) { + console.log(`${chalk.cyan(packageName)} is already linked to ${linkInfo.path}. Please unlink and try again.`); + } + + if (isLinked(path.join(kibanaPath, 'node_modules', packageName), echDir)) { + ora( + `Selected ${chalk.cyan(kibanaPackageInfo.name)} application already has ${chalk.cyan(packageName)} link`, + ).succeed(); + console.log(` + To remove this link run ${chalk.cyan('yarn link:charts')} and select the option to ${chalk.bold.underline( + 'Unlink', + )}`); + return; + } + } + + console.log(` + Please ensure kibana is bootstrapped and running: + cd ${kibanaPath} + + ${chalk.dim('# start elasticsearch or configure kibana to point at remote elasticsearch cluster')} + yarn es snapshot --license trial --password changeme -E node.attr.hot_node=true + + ${chalk.dim('# boostrap and start kibana')} + yarn kbn bootstrap --no-cache + yarn start +`); + await writeLinkInfo(tempDir, { + name: kibanaPackageInfo.name, + path: kibanaPath, + created: new Date(), + }); + const { isReady } = await inquirer.prompt({ + name: 'isReady', + message: `Press ${chalk.italic('Y')} to continue when kibana is running or ${chalk.italic('N')} to cancel.`, + type: 'confirm', + default: true, + }); + + if (!isReady) { + console.log('Please ensure kibana is running before linking charts'); + return; + } + + await linkPackage(echDir, kibanaPath, packageName); + + cps.push( + await spawnWatch('yarn build:watch --preserveWatchOutput --pretty', packageName, { + cwd: echDir, + errorStr: 'error TS', + stopStr: 'Found 0 errors. Watching for file changes', + startStr: 'File change detected. Starting incremental compilation', + onUpdate: () => replaceModules(echDir, kibanaPath, linkedPackages, echPackageContent), + }), + ); + + const kbnSharedPackage = path.join(kibanaPath, 'packages/kbn-ui-shared-deps'); + cps.push( + await spawnWatch('yarn kbn:watch', '@kbn/ui-shared-dep', { + cwd: kbnSharedPackage, + errorStr: 'ERROR', + stopStr: 'webpack completed', + startStr: 'Running webpack compilation', + }), + ); + + await writeLinkInfo(tempDir, { + name: kibanaPackageInfo.name, + path: kibanaPath, + created: new Date(), + }); + + console.log(` + Link Successful, please keep this tab running to watch for file changes. + Refresh kibana to see all new file changes, each time files are rebuilt. + When finished end this process and run ${chalk.cyan( + 'yarn link:charts', + )} and select the option to ${chalk.bold.underline('Unlink')} to cleanup link changes. + `); + } else { + const kibanaPath = linkInfo.path; + if (!kibanaPath) { + ora(`No links found for ${chalk.cyan(packageName)}`).warn(); + return; + } + + if (action === 'Watch mode') { + cps.push( + await spawnWatch('yarn build:watch --preserveWatchOutput', packageName, { + cwd: echDir, + errorStr: ': error TS', + stopStr: 'Found 0 errors. Watching for file changes', + startStr: 'File change detected. Starting incremental compilation', + onUpdate: () => replaceModules(echDir, kibanaPath, linkedPackages, echPackageContent), + }), + ); + + const kbnSharedPackage = path.join(kibanaPath, 'packages/kbn-ui-shared-deps'); + cps.push( + await spawnWatch('yarn kbn:watch', '@kbn/ui-shared-dep', { + cwd: kbnSharedPackage, + errorStr: 'ERROR', + stopStr: 'webpack completed', + startStr: 'Running webpack compilation', + }), + ); + + return; + } + + await exec('yarn build', `Restoring build ${chalk.dim(packageName)}`, { cwd: echDir, errorStr: ': error TS' }); + const chartsFileRestored = await unlinkPackage(linkInfo.path, packageName); + + await writeLinkInfo(tempDir, {}); + + if (chartsFileRestored) { + try { + const kbnSharedPackage = path.join(kibanaPath, 'packages/kbn-ui-shared-deps'); + await exec('yarn build --dev', `Restoring build ${chalk.dim('@kbn/ui-shared-dep')}`, { + errorStr: 'ERROR', + cwd: kbnSharedPackage, + }); + + console.log(` + Unlink Successful. Kibana has been restored to the pre-linked state. + Please refresh kibana to see restored state.`); + return; + } catch { + // fallthrough + } + } + + console.log(` +Unlink Complete. Kibana was ${chalk.underline('not')} restored to the pre-linked state. Please run ${chalk.cyan( + 'yarn kbn bootstrap --no-cache', + )}`); + } +}; diff --git a/packages/link_kibana/package.json b/packages/link_kibana/package.json new file mode 100644 index 0000000000..b69bb8b4b6 --- /dev/null +++ b/packages/link_kibana/package.json @@ -0,0 +1,14 @@ +{ + "name": "link-kibana", + "description": "Utility to aid in linking charts to kinana", + "license": "Apache-2.0", + "version": "1.0.0", + "main": "index.js", + "dependencies": { + "chalk": "^4.1.1", + "change-case": "^4.1.2", + "glob": "^7.1.7", + "inquirer": "^8.0.0", + "ora": "^5.4.0" + } +} diff --git a/packages/link_kibana/process_utils.js b/packages/link_kibana/process_utils.js new file mode 100644 index 0000000000..22b6d87ce2 --- /dev/null +++ b/packages/link_kibana/process_utils.js @@ -0,0 +1,152 @@ +/* + * 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. + */ + +const childProcess = require('child_process'); + +const chalk = require('chalk'); +const ora = require('ora'); + +const printError = (error) => + console.log( + error + .toString() + .split('\n') + .map((line) => `\t${line}`) + .join('\n'), + ); + +const parseBuffer = (buf) => { + return unescape(escape(buf.toString())).replace( + // eslint-disable-next-line no-control-regex + /[\u001B\u009B][#();?[]*(?:\d{1,4}(?:;\d{0,4})*)?[\d<=>A-ORZcf-nqry]/g, + '', + ); +}; + +const printErrorMsg = () => { + console.log(chalk.redBright.bold('\n An Error occured, please resolve the issue(s) below:\n')); +}; + +const exec = async (command, message, { cwd, errorMsg, errorStr } = {}) => { + const spinner = ora(message).start(); + await new Promise((resolve) => { + childProcess.exec(command, { cwd, timeout: 2 * 60 * 1000 }, (error, stdoutBuf, stderrBuf) => { + const stdout = parseBuffer(stdoutBuf); + const stderr = parseBuffer(stderrBuf); + + if (stdout && !spinner.isSpinning) { + spinner.start(); + } + + if (errorStr) { + const errors = []; + + if (stderr && stderr.includes(errorStr)) { + errors.push(stderr); + } + + if (stdout && stdout.includes(errorStr)) { + errors.push(stdout); + } + + if (errors.length > 0) { + spinner.fail(); + printErrorMsg(); + errors.forEach(printError); + return; + } + } + + if (error) { + spinner.fail(errorMsg || error); + return; + } + + spinner.succeed(); + resolve(stdout); + }); + }); +}; + +const spawnWatch = (command, packageName, { cwd, startStr, stopStr, onUpdate, errorStr } = {}) => + new Promise((resolve, reject) => { + console.log(`Starting build of ${chalk.cyan.bold(packageName)} in detatched watch mode`); + let spinner = ora(`Building initial files ${chalk.dim(packageName)}`).start(); + + const cp = childProcess.spawn(command, [], { cwd, detached: true, shell: true }); + + if (!stopStr) { + spinner.succeed(); + resolve(); + } else { + let hasError = false; + cp.stdout.on('data', (dataBuffer) => { + const stdout = parseBuffer(dataBuffer); + if (startStr && !spinner.isSpinning && stdout.includes(startStr)) { + spinner = ora(`Building changed files ${chalk.dim(packageName)}`).start(); + return; + } + + if (errorStr) { + if (stdout.includes(errorStr)) { + if (!hasError) { + spinner.fail(); + printErrorMsg(); + hasError = true; + } + printError(dataBuffer); + return; + } + hasError = false; + } + + if (spinner.isSpinning && stdout.includes(stopStr)) { + spinner.succeed(); + if (onUpdate) onUpdate().then(resolve).catch(reject); + else resolve(); + } + }); + + if (errorStr) { + cp.stderr.on('data', (dataBuffer) => { + const stderr = parseBuffer(dataBuffer); + if (stderr.includes(errorStr)) { + if (!hasError) { + spinner.fail(); + printErrorMsg(); + hasError = true; + } + printError(dataBuffer); + return; + } + hasError = false; + }); + } + } + + cp.on('error', (error) => { + spinner.fail(error); + reject(error); + throw new Error(error); + }); + + return cp; + }); + +module.exports = { exec, spawnWatch }; diff --git a/packages/link_kibana/replace_modules.js b/packages/link_kibana/replace_modules.js new file mode 100644 index 0000000000..c75a9b6c70 --- /dev/null +++ b/packages/link_kibana/replace_modules.js @@ -0,0 +1,87 @@ +/* + * 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. + */ + +const fs = require('fs'); +const path = require('path'); + +const chalk = require('chalk'); +const glob = require('glob'); +const ora = require('ora'); + +const addConsoleFlag = (dirPath, packageContent) => { + const filePath = path.join(dirPath, 'dist/index.js'); + try { + const existingContent = fs.readFileSync(filePath, 'utf8'); + + if (!existingContent.includes('LINKED CONSOLE FLAG')) { + const appendContent = ` +// LINKED CONSOLE FLAG +window.ech_linked_package = JSON.parse(\`${JSON.stringify(packageContent)}\`); +console.log( + '%cLinked ${packageContent.name}!', + 'font-weight: bold; font-size: 30px;color: #f04d9a; text-shadow: 2px 2px 0 #14abf5 , 4px 4px 0 #fec709 , 6px 6px 0 #00c1b4', +); +console.log('Linked charts dir:', '${dirPath}'); +console.log('Linked charts package:', window.ech_linked_package); +`; + fs.appendFileSync(filePath, appendContent); + } + } catch { + // unable to add console flag + } +}; + +const replaceModules = async (libDir, appDir, linkedPackages, packageContent) => { + if (linkedPackages.length === 0) return; + + const spinner = ora(`Replacing package links ${chalk.dim(`(${linkedPackages.join(',')})`)}`).start(); + + await new Promise((resolve, reject) => { + const cwd = path.join(libDir, 'dist'); + // TODO find out why this path doesn't work with the linked lib + // const moduleDir = path.join(appDir, 'node_modules'); + const moduleDir = path.join(path.dirname(appDir), '../../', path.basename(appDir), 'node_modules'); + const re = new RegExp(`require\\("(?:.*?\\/)*(${linkedPackages.join('|')})"\\)`, 'g'); + + glob('**/*.js', { ignore: ['**/*.map.js'], cwd }, (error, files) => { + if (error) { + spinner.fail(error); + reject(error); + } + + files.forEach((file) => { + const fullPath = path.join(cwd, file); + const fileContent = fs.readFileSync(fullPath, { encoding: 'utf8' }); + const relativeModulesPath = path.relative(fullPath, moduleDir); + + if (re.test(fileContent)) { + const newFileContent = fileContent.replace(re, `require("${relativeModulesPath}/$1")`); + + fs.writeFileSync(fullPath, newFileContent); + } + }); + addConsoleFlag(libDir, packageContent); + + spinner.succeed(); + resolve(); + }); + }); +}; + +module.exports = { replaceModules }; diff --git a/packages/link_kibana/utils.js b/packages/link_kibana/utils.js new file mode 100644 index 0000000000..ae76964f5a --- /dev/null +++ b/packages/link_kibana/utils.js @@ -0,0 +1,166 @@ +/* + * 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. + */ + +const { createHash } = require('crypto'); +const fs = require('fs'); +const os = require('os'); +const path = require('path'); +const { promisify } = require('util'); + +const chalk = require('chalk'); +const { snakeCase } = require('change-case'); + +const { exec } = require('./process_utils'); + +const exists = async (somePath) => { + try { + await promisify(fs.access)(somePath, fs.constants.F_OK); + return true; + } catch (error) { + if (error.code !== 'ENOENT') throw new Error(error); + return false; + } +}; + +const hashValue = (str) => { + const hash = createHash('md5'); + hash.update(str); + return hash.digest('hex'); +}; + +const getPackageInfo = async (pkgDir) => { + const filePath = pkgDir.endsWith('/package.json') ? pkgDir : path.join(pkgDir, 'package.json'); + + try { + return JSON.parse(await promisify(fs.readFile)(filePath, 'utf8')); + } catch (error) { + if (error.code === 'ENOENT') { + throw new Error(`Missing package.json file at ${filePath}`); + } + throw new Error(error); + } +}; + +const createDir = async (dirPath) => { + try { + await promisify(fs.mkdir)(dirPath); + } catch (error) { + if (error.code !== 'EEXIST') throw new Error(error); + } +}; + +/** + * Gets or creates temp directory for given package name. + * Used to store linked information + */ +const getTempDir = async (cwd, packageName) => { + const tempPrefix = `link_${snakeCase(packageName)}_`; + const repoHash = hashValue(cwd); + const tempPkgDirName = (await promisify(fs.readdir)(os.tmpdir())).find((p) => p.startsWith(tempPrefix)); + const tempPkgDir = tempPkgDirName + ? path.join(os.tmpdir(), tempPkgDirName) + : await promisify(fs.mkdtemp)(path.join(os.tmpdir(), tempPrefix)); + const tempRepoDir = path.join(tempPkgDir, repoHash); + await createDir(tempRepoDir); + + return tempRepoDir; +}; + +const getLinkInfo = async (tempPath) => { + try { + const infoPath = path.join(tempPath, 'link.json'); + return JSON.parse(await promisify(fs.readFile)(infoPath, 'utf8')); + } catch { + return { links: [] }; + } +}; + +const writeLinkInfo = async (tempPath, linkInfo) => { + const infoPath = path.join(tempPath, 'link.json'); + const data = JSON.stringify(linkInfo, null, 2); + + await promisify(fs.writeFile)(infoPath, data, 'utf8'); +}; + +const isLinked = (dirPath, linkPath) => { + try { + if (!fs.lstatSync(dirPath).isSymbolicLink()) { + return false; + } + } catch (error) { + if (error.code === 'ENOENT') return false; + throw new Error(error); + } + + if (linkPath) { + // verify linked to expected target + return fs.readlinkSync(dirPath) === linkPath; + } + + return true; +}; + +const restorePackage = async (appDir, packageName) => { + try { + const errorMsg = `Unable to restore ${chalk.cyan(packageName)} package in ${chalk.cyan(path.basename(appDir))}`; + await exec( + `yarn add ${packageName} --force --exact`, + `Restoring ${chalk.cyan(packageName)} in ${chalk.cyan(path.basename(appDir))}`, + { + cwd: appDir, + errorMsg, + }, + ); + return true; + } catch { + return false; + } +}; + +const linkPackage = async (target, linkPath, packageName) => { + const linkPackagePath = path.join(linkPath, 'node_modules', packageName); + const relativeLinkPath = path.relative(target, linkPackagePath); + if (await exists(linkPackagePath)) { + await promisify(fs.rm)(linkPackagePath, { recursive: true, force: true }); + } + await promisify(fs.symlink)(target, relativeLinkPath); +}; + +const unlinkPackage = async (linkPath, packageName) => { + const linkPackagePath = path.join(linkPath, 'node_modules', packageName); + + if (isLinked(linkPackagePath)) { + await promisify(fs.unlink)(linkPackagePath); + } + + return await restorePackage(linkPath, packageName); +}; + +module.exports = { + exists, + hashValue, + getPackageInfo, + createDir, + getTempDir, + getLinkInfo, + writeLinkInfo, + isLinked, + linkPackage, + unlinkPackage, +}; diff --git a/packages/link_kibana/yarn.lock b/packages/link_kibana/yarn.lock new file mode 100644 index 0000000000..1950910b67 --- /dev/null +++ b/packages/link_kibana/yarn.lock @@ -0,0 +1,540 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +ansi-escapes@^4.2.1: + version "4.3.2" + resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-4.3.2.tgz#6b2291d1db7d98b6521d5f1efa42d0f3a9feb65e" + integrity sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ== + dependencies: + type-fest "^0.21.3" + +ansi-regex@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.0.tgz#388539f55179bf39339c81af30a654d69f87cb75" + integrity sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg== + +ansi-styles@^4.1.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.3.0.tgz#edd803628ae71c04c85ae7a0906edad34b648937" + integrity sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg== + dependencies: + color-convert "^2.0.1" + +balanced-match@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" + integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== + +base64-js@^1.3.1: + version "1.5.1" + resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a" + integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA== + +bl@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/bl/-/bl-4.1.0.tgz#451535264182bec2fbbc83a62ab98cf11d9f7b3a" + integrity sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w== + dependencies: + buffer "^5.5.0" + inherits "^2.0.4" + readable-stream "^3.4.0" + +brace-expansion@^1.1.7: + version "1.1.11" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" + integrity sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA== + dependencies: + balanced-match "^1.0.0" + concat-map "0.0.1" + +buffer@^5.5.0: + version "5.7.1" + resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.7.1.tgz#ba62e7c13133053582197160851a8f648e99eed0" + integrity sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ== + dependencies: + base64-js "^1.3.1" + ieee754 "^1.1.13" + +camel-case@^4.1.2: + version "4.1.2" + resolved "https://registry.yarnpkg.com/camel-case/-/camel-case-4.1.2.tgz#9728072a954f805228225a6deea6b38461e1bd5a" + integrity sha512-gxGWBrTT1JuMx6R+o5PTXMmUnhnVzLQ9SNutD4YqKtI6ap897t3tKECYla6gCWEkplXnlNybEkZg9GEGxKFCgw== + dependencies: + pascal-case "^3.1.2" + tslib "^2.0.3" + +capital-case@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/capital-case/-/capital-case-1.0.4.tgz#9d130292353c9249f6b00fa5852bee38a717e669" + integrity sha512-ds37W8CytHgwnhGGTi88pcPyR15qoNkOpYwmMMfnWqqWgESapLqvDx6huFjQ5vqWSn2Z06173XNA7LtMOeUh1A== + dependencies: + no-case "^3.0.4" + tslib "^2.0.3" + upper-case-first "^2.0.2" + +chalk@^4.1.0, chalk@^4.1.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.1.tgz#c80b3fab28bf6371e6863325eee67e618b77e6ad" + integrity sha512-diHzdDKxcU+bAsUboHLPEDQiw0qEe0qd7SYUn3HgcFlWgbDcfLGswOHYeGrHKzG9z6UYf01d9VFMfZxPM1xZSg== + dependencies: + ansi-styles "^4.1.0" + supports-color "^7.1.0" + +change-case@^4.1.2: + version "4.1.2" + resolved "https://registry.yarnpkg.com/change-case/-/change-case-4.1.2.tgz#fedfc5f136045e2398c0410ee441f95704641e12" + integrity sha512-bSxY2ws9OtviILG1EiY5K7NNxkqg/JnRnFxLtKQ96JaviiIxi7djMrSd0ECT9AC+lttClmYwKw53BWpOMblo7A== + dependencies: + camel-case "^4.1.2" + capital-case "^1.0.4" + constant-case "^3.0.4" + dot-case "^3.0.4" + header-case "^2.0.4" + no-case "^3.0.4" + param-case "^3.0.4" + pascal-case "^3.1.2" + path-case "^3.0.4" + sentence-case "^3.0.4" + snake-case "^3.0.4" + tslib "^2.0.3" + +chardet@^0.7.0: + version "0.7.0" + resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e" + integrity sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA== + +cli-cursor@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-3.1.0.tgz#264305a7ae490d1d03bf0c9ba7c925d1753af307" + integrity sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw== + dependencies: + restore-cursor "^3.1.0" + +cli-spinners@^2.5.0: + version "2.6.0" + resolved "https://registry.yarnpkg.com/cli-spinners/-/cli-spinners-2.6.0.tgz#36c7dc98fb6a9a76bd6238ec3f77e2425627e939" + integrity sha512-t+4/y50K/+4xcCRosKkA7W4gTr1MySvLV0q+PxmG7FJ5g+66ChKurYjxBCjHggHH3HA5Hh9cy+lcUGWDqVH+4Q== + +cli-width@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-3.0.0.tgz#a2f48437a2caa9a22436e794bf071ec9e61cedf6" + integrity sha512-FxqpkPPwu1HjuN93Omfm4h8uIanXofW0RxVEW3k5RKx+mJJYSthzNhp32Kzxxy3YAEZ/Dc/EWN1vZRY0+kOhbw== + +clone@^1.0.2: + version "1.0.4" + resolved "https://registry.yarnpkg.com/clone/-/clone-1.0.4.tgz#da309cc263df15994c688ca902179ca3c7cd7c7e" + integrity sha1-2jCcwmPfFZlMaIypAheco8fNfH4= + +color-convert@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3" + integrity sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ== + dependencies: + color-name "~1.1.4" + +color-name@~1.1.4: + version "1.1.4" + resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" + integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== + +concat-map@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" + integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s= + +constant-case@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/constant-case/-/constant-case-3.0.4.tgz#3b84a9aeaf4cf31ec45e6bf5de91bdfb0589faf1" + integrity sha512-I2hSBi7Vvs7BEuJDr5dDHfzb/Ruj3FyvFyh7KLilAjNQw3Be+xgqUBA2W6scVEcL0hL1dwPRtIqEPVUCKkSsyQ== + dependencies: + no-case "^3.0.4" + tslib "^2.0.3" + upper-case "^2.0.2" + +defaults@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/defaults/-/defaults-1.0.3.tgz#c656051e9817d9ff08ed881477f3fe4019f3ef7d" + integrity sha1-xlYFHpgX2f8I7YgUd/P+QBnz730= + dependencies: + clone "^1.0.2" + +dot-case@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/dot-case/-/dot-case-3.0.4.tgz#9b2b670d00a431667a8a75ba29cd1b98809ce751" + integrity sha512-Kv5nKlh6yRrdrGvxeJ2e5y2eRUpkUosIW4A2AS38zwSz27zu7ufDwQPi5Jhs3XAlGNetl3bmnGhQsMtkKJnj3w== + dependencies: + no-case "^3.0.4" + tslib "^2.0.3" + +emoji-regex@^8.0.0: + version "8.0.0" + resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37" + integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== + +escape-string-regexp@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" + integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ= + +external-editor@^3.0.3: + version "3.1.0" + resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-3.1.0.tgz#cb03f740befae03ea4d283caed2741a83f335495" + integrity sha512-hMQ4CX1p1izmuLYyZqLMO/qGNw10wSv9QDCPfzXfyFrOaCSSoRfqE1Kf1s5an66J5JZC62NewG+mK49jOCtQew== + dependencies: + chardet "^0.7.0" + iconv-lite "^0.4.24" + tmp "^0.0.33" + +figures@^3.0.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/figures/-/figures-3.2.0.tgz#625c18bd293c604dc4a8ddb2febf0c88341746af" + integrity sha512-yaduQFRKLXYOGgEn6AZau90j3ggSOyiqXU0F9JZfeXYhNa+Jk4X+s45A2zg5jns87GAFa34BBm2kXw4XpNcbdg== + dependencies: + escape-string-regexp "^1.0.5" + +fs.realpath@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" + integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8= + +glob@^7.1.7: + version "7.1.7" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.7.tgz#3b193e9233f01d42d0b3f78294bbeeb418f94a90" + integrity sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ== + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.0.4" + once "^1.3.0" + path-is-absolute "^1.0.0" + +has-flag@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" + integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ== + +header-case@^2.0.4: + version "2.0.4" + resolved "https://registry.yarnpkg.com/header-case/-/header-case-2.0.4.tgz#5a42e63b55177349cf405beb8d775acabb92c063" + integrity sha512-H/vuk5TEEVZwrR0lp2zed9OCo1uAILMlx0JEMgC26rzyJJ3N1v6XkwHHXJQdR2doSjcGPM6OKPYoJgf0plJ11Q== + dependencies: + capital-case "^1.0.4" + tslib "^2.0.3" + +iconv-lite@^0.4.24: + version "0.4.24" + resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b" + integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA== + dependencies: + safer-buffer ">= 2.1.2 < 3" + +ieee754@^1.1.13: + version "1.2.1" + resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352" + integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA== + +inflight@^1.0.4: + version "1.0.6" + resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" + integrity sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk= + dependencies: + once "^1.3.0" + wrappy "1" + +inherits@2, inherits@^2.0.3, inherits@^2.0.4: + version "2.0.4" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" + integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== + +inquirer@^8.0.0: + version "8.0.0" + resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-8.0.0.tgz#957a46db1abcf0fdd2ab82deb7470e90afc7d0ac" + integrity sha512-ON8pEJPPCdyjxj+cxsYRe6XfCJepTxANdNnTebsTuQgXpRyZRRT9t4dJwjRubgmvn20CLSEnozRUayXyM9VTXA== + dependencies: + ansi-escapes "^4.2.1" + chalk "^4.1.0" + cli-cursor "^3.1.0" + cli-width "^3.0.0" + external-editor "^3.0.3" + figures "^3.0.0" + lodash "^4.17.21" + mute-stream "0.0.8" + run-async "^2.4.0" + rxjs "^6.6.6" + string-width "^4.1.0" + strip-ansi "^6.0.0" + through "^2.3.6" + +is-fullwidth-code-point@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d" + integrity sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg== + +is-interactive@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-interactive/-/is-interactive-1.0.0.tgz#cea6e6ae5c870a7b0a0004070b7b587e0252912e" + integrity sha512-2HvIEKRoqS62guEC+qBjpvRubdX910WCMuJTZ+I9yvqKU2/12eSL549HMwtabb4oupdj2sMP50k+XJfB/8JE6w== + +is-unicode-supported@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz#3f26c76a809593b52bfa2ecb5710ed2779b522a7" + integrity sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw== + +lodash@^4.17.21: + version "4.17.21" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" + integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== + +log-symbols@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-4.1.0.tgz#3fbdbb95b4683ac9fc785111e792e558d4abd503" + integrity sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg== + dependencies: + chalk "^4.1.0" + is-unicode-supported "^0.1.0" + +lower-case@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/lower-case/-/lower-case-2.0.2.tgz#6fa237c63dbdc4a82ca0fd882e4722dc5e634e28" + integrity sha512-7fm3l3NAF9WfN6W3JOmf5drwpVqX78JtoGJ3A6W0a6ZnldM41w2fV5D490psKFTpMds8TJse/eHLFFsNHHjHgg== + dependencies: + tslib "^2.0.3" + +mimic-fn@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b" + integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg== + +minimatch@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" + integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA== + dependencies: + brace-expansion "^1.1.7" + +mute-stream@0.0.8: + version "0.0.8" + resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d" + integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA== + +no-case@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/no-case/-/no-case-3.0.4.tgz#d361fd5c9800f558551a8369fc0dcd4662b6124d" + integrity sha512-fgAN3jGAh+RoxUGZHTSOLJIqUc2wmoBwGR4tbpNAKmmovFoWq0OdRkb0VkldReO2a2iBT/OEulG9XSUc10r3zg== + dependencies: + lower-case "^2.0.2" + tslib "^2.0.3" + +once@^1.3.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" + integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E= + dependencies: + wrappy "1" + +onetime@^5.1.0: + version "5.1.2" + resolved "https://registry.yarnpkg.com/onetime/-/onetime-5.1.2.tgz#d0e96ebb56b07476df1dd9c4806e5237985ca45e" + integrity sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg== + dependencies: + mimic-fn "^2.1.0" + +ora@^5.4.0: + version "5.4.0" + resolved "https://registry.yarnpkg.com/ora/-/ora-5.4.0.tgz#42eda4855835b9cd14d33864c97a3c95a3f56bf4" + integrity sha512-1StwyXQGoU6gdjYkyVcqOLnVlbKj+6yPNNOxJVgpt9t4eksKjiriiHuxktLYkgllwk+D6MbC4ihH84L1udRXPg== + dependencies: + bl "^4.1.0" + chalk "^4.1.0" + cli-cursor "^3.1.0" + cli-spinners "^2.5.0" + is-interactive "^1.0.0" + is-unicode-supported "^0.1.0" + log-symbols "^4.1.0" + strip-ansi "^6.0.0" + wcwidth "^1.0.1" + +os-tmpdir@~1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" + integrity sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ= + +param-case@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/param-case/-/param-case-3.0.4.tgz#7d17fe4aa12bde34d4a77d91acfb6219caad01c5" + integrity sha512-RXlj7zCYokReqWpOPH9oYivUzLYZ5vAPIfEmCTNViosC78F8F0H9y7T7gG2M39ymgutxF5gcFEsyZQSph9Bp3A== + dependencies: + dot-case "^3.0.4" + tslib "^2.0.3" + +pascal-case@^3.1.2: + version "3.1.2" + resolved "https://registry.yarnpkg.com/pascal-case/-/pascal-case-3.1.2.tgz#b48e0ef2b98e205e7c1dae747d0b1508237660eb" + integrity sha512-uWlGT3YSnK9x3BQJaOdcZwrnV6hPpd8jFH1/ucpiLRPh/2zCVJKS19E4GvYHvaCcACn3foXZ0cLB9Wrx1KGe5g== + dependencies: + no-case "^3.0.4" + tslib "^2.0.3" + +path-case@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/path-case/-/path-case-3.0.4.tgz#9168645334eb942658375c56f80b4c0cb5f82c6f" + integrity sha512-qO4qCFjXqVTrcbPt/hQfhTQ+VhFsqNKOPtytgNKkKxSoEp3XPUQ8ObFuePylOIok5gjn69ry8XiULxCwot3Wfg== + dependencies: + dot-case "^3.0.4" + tslib "^2.0.3" + +path-is-absolute@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" + integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18= + +readable-stream@^3.4.0: + version "3.6.0" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198" + integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA== + dependencies: + inherits "^2.0.3" + string_decoder "^1.1.1" + util-deprecate "^1.0.1" + +restore-cursor@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-3.1.0.tgz#39f67c54b3a7a58cea5236d95cf0034239631f7e" + integrity sha512-l+sSefzHpj5qimhFSE5a8nufZYAM3sBSVMAPtYkmC+4EH2anSGaEMXSD0izRQbu9nfyQ9y5JrVmp7E8oZrUjvA== + dependencies: + onetime "^5.1.0" + signal-exit "^3.0.2" + +run-async@^2.4.0: + version "2.4.1" + resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.4.1.tgz#8440eccf99ea3e70bd409d49aab88e10c189a455" + integrity sha512-tvVnVv01b8c1RrA6Ep7JkStj85Guv/YrMcwqYQnwjsAS2cTmmPGBBjAjpCW7RrSodNSoE2/qg9O4bceNvUuDgQ== + +rxjs@^6.6.6: + version "6.6.7" + resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.6.7.tgz#90ac018acabf491bf65044235d5863c4dab804c9" + integrity sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ== + dependencies: + tslib "^1.9.0" + +safe-buffer@~5.2.0: + version "5.2.1" + resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" + integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ== + +"safer-buffer@>= 2.1.2 < 3": + version "2.1.2" + resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" + integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== + +sentence-case@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/sentence-case/-/sentence-case-3.0.4.tgz#3645a7b8c117c787fde8702056225bb62a45131f" + integrity sha512-8LS0JInaQMCRoQ7YUytAo/xUu5W2XnQxV2HI/6uM6U7CITS1RqPElr30V6uIqyMKM9lJGRVFy5/4CuzcixNYSg== + dependencies: + no-case "^3.0.4" + tslib "^2.0.3" + upper-case-first "^2.0.2" + +signal-exit@^3.0.2: + version "3.0.3" + resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.3.tgz#a1410c2edd8f077b08b4e253c8eacfcaf057461c" + integrity sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA== + +snake-case@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/snake-case/-/snake-case-3.0.4.tgz#4f2bbd568e9935abdfd593f34c691dadb49c452c" + integrity sha512-LAOh4z89bGQvl9pFfNF8V146i7o7/CqFPbqzYgP+yYzDIDeS9HaNFtXABamRW+AQzEVODcvE79ljJ+8a9YSdMg== + dependencies: + dot-case "^3.0.4" + tslib "^2.0.3" + +string-width@^4.1.0: + version "4.2.2" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.2.tgz#dafd4f9559a7585cfba529c6a0a4f73488ebd4c5" + integrity sha512-XBJbT3N4JhVumXE0eoLU9DCjcaF92KLNqTmFCnG1pf8duUxFGwtP6AD6nkjw9a3IdiRtL3E2w3JDiE/xi3vOeA== + dependencies: + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.0" + +string_decoder@^1.1.1: + version "1.3.0" + resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e" + integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA== + dependencies: + safe-buffer "~5.2.0" + +strip-ansi@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.0.tgz#0b1571dd7669ccd4f3e06e14ef1eed26225ae532" + integrity sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w== + dependencies: + ansi-regex "^5.0.0" + +supports-color@^7.1.0: + version "7.2.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da" + integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw== + dependencies: + has-flag "^4.0.0" + +through@^2.3.6: + version "2.3.8" + resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" + integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU= + +tmp@^0.0.33: + version "0.0.33" + resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9" + integrity sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw== + dependencies: + os-tmpdir "~1.0.2" + +tslib@^1.9.0: + version "1.14.1" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" + integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== + +tslib@^2.0.3: + version "2.2.0" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.2.0.tgz#fb2c475977e35e241311ede2693cee1ec6698f5c" + integrity sha512-gS9GVHRU+RGn5KQM2rllAlR3dU6m7AcpJKdtH8gFvQiC4Otgk98XnmMU+nZenHt/+VhnBPWwgrJsyrdcw6i23w== + +type-fest@^0.21.3: + version "0.21.3" + resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.21.3.tgz#d260a24b0198436e133fa26a524a6d65fa3b2e37" + integrity sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w== + +upper-case-first@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/upper-case-first/-/upper-case-first-2.0.2.tgz#992c3273f882abd19d1e02894cc147117f844324" + integrity sha512-514ppYHBaKwfJRK/pNC6c/OxfGa0obSnAl106u97Ed0I625Nin96KAjttZF6ZL3e1XLtphxnqrOi9iWgm+u+bg== + dependencies: + tslib "^2.0.3" + +upper-case@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/upper-case/-/upper-case-2.0.2.tgz#d89810823faab1df1549b7d97a76f8662bae6f7a" + integrity sha512-KgdgDGJt2TpuwBUIjgG6lzw2GWFRCW9Qkfkiv0DxqHHLYJHmtmdUIKcZd8rHgFSjopVTlw6ggzCm1b8MFQwikg== + dependencies: + tslib "^2.0.3" + +util-deprecate@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" + integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8= + +wcwidth@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/wcwidth/-/wcwidth-1.0.1.tgz#f0b0dcf915bc5ff1528afadb2c0e17b532da2fe8" + integrity sha1-8LDc+RW8X/FSivrbLA4XtTLaL+g= + dependencies: + defaults "^1.0.3" + +wrappy@1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" + integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= diff --git a/tsconfig.lib-nocomments.json b/tsconfig.lib-nocomments.json index f2480c7c3c..1efea37f5a 100644 --- a/tsconfig.lib-nocomments.json +++ b/tsconfig.lib-nocomments.json @@ -1,9 +1,9 @@ { + "extends": "./tsconfig.lib", "compilerOptions": { "removeComments": true, "declaration": false, "declarationMap": false }, - "files": [], - "extends": "./tsconfig.lib" + "files": [] } diff --git a/tsconfig.lib.json b/tsconfig.lib.json index 87e0d270bf..822a5bbca1 100644 --- a/tsconfig.lib.json +++ b/tsconfig.lib.json @@ -1,9 +1,9 @@ { + "extends": "./tsconfig", "compilerOptions": { "noUnusedLocals": true, "removeComments": false }, - "extends": "./tsconfig", "files": [], "include": ["src/**/*"], "exclude": ["**/*.test.*", "**/__mocks__", "src/mocks/**/*", "src/utils/data_samples/**/*"] diff --git a/yarn.lock b/yarn.lock index ced015905d..95fc47fa46 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11474,8 +11474,9 @@ eslint-module-utils@^2.6.0: debug "^2.6.9" pkg-dir "^2.0.0" -"eslint-plugin-elastic-charts@file:./packages/eslint-plugin-elastic-charts": - version "1.0.0" +"eslint-plugin-elastic-charts@link:./packages/eslint-plugin-elastic-charts": + version "0.0.0" + uid "" eslint-plugin-eslint-comments@^3.2.0: version "3.2.0" @@ -16066,6 +16067,10 @@ lines-and-columns@^1.1.6: resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.1.6.tgz#1c00c743b433cd0a4e80758f7b64a57440d9ff00" integrity sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA= +"link-kibana@link:./packages/link_kibana": + version "0.0.0" + uid "" + lint-staged@^10.5.3: version "10.5.3" resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-10.5.3.tgz#c682838b3eadd4c864d1022da05daa0912fb1da5" From 125e3de766c85e22ce497768a5a18efded1eebaa Mon Sep 17 00:00:00 2001 From: nickofthyme Date: Wed, 19 May 2021 22:35:22 -0500 Subject: [PATCH 02/10] fix: console flag statement --- packages/link_kibana/main.js | 4 ++-- packages/link_kibana/replace_modules.js | 12 +++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/link_kibana/main.js b/packages/link_kibana/main.js index 642e47ec5a..c945e0c4cd 100644 --- a/packages/link_kibana/main.js +++ b/packages/link_kibana/main.js @@ -146,7 +146,7 @@ to link charts with another application use ${chalk.cyan( errorStr: 'error TS', stopStr: 'Found 0 errors. Watching for file changes', startStr: 'File change detected. Starting incremental compilation', - onUpdate: () => replaceModules(echDir, kibanaPath, linkedPackages, echPackageContent), + onUpdate: () => replaceModules(echDir, kibanaPath, linkedPackages), }), ); @@ -187,7 +187,7 @@ to link charts with another application use ${chalk.cyan( errorStr: ': error TS', stopStr: 'Found 0 errors. Watching for file changes', startStr: 'File change detected. Starting incremental compilation', - onUpdate: () => replaceModules(echDir, kibanaPath, linkedPackages, echPackageContent), + onUpdate: () => replaceModules(echDir, kibanaPath, linkedPackages), }), ); diff --git a/packages/link_kibana/replace_modules.js b/packages/link_kibana/replace_modules.js index c75a9b6c70..eda1ec551d 100644 --- a/packages/link_kibana/replace_modules.js +++ b/packages/link_kibana/replace_modules.js @@ -24,7 +24,7 @@ const chalk = require('chalk'); const glob = require('glob'); const ora = require('ora'); -const addConsoleFlag = (dirPath, packageContent) => { +const addConsoleFlag = (dirPath) => { const filePath = path.join(dirPath, 'dist/index.js'); try { const existingContent = fs.readFileSync(filePath, 'utf8'); @@ -32,13 +32,11 @@ const addConsoleFlag = (dirPath, packageContent) => { if (!existingContent.includes('LINKED CONSOLE FLAG')) { const appendContent = ` // LINKED CONSOLE FLAG -window.ech_linked_package = JSON.parse(\`${JSON.stringify(packageContent)}\`); console.log( - '%cLinked ${packageContent.name}!', + '\\n%cLinked @elastic/charts!', 'font-weight: bold; font-size: 30px;color: #f04d9a; text-shadow: 2px 2px 0 #14abf5 , 4px 4px 0 #fec709 , 6px 6px 0 #00c1b4', + '\\n\\ndir:', '${dirPath}\\n\\n' ); -console.log('Linked charts dir:', '${dirPath}'); -console.log('Linked charts package:', window.ech_linked_package); `; fs.appendFileSync(filePath, appendContent); } @@ -47,7 +45,7 @@ console.log('Linked charts package:', window.ech_linked_package); } }; -const replaceModules = async (libDir, appDir, linkedPackages, packageContent) => { +const replaceModules = async (libDir, appDir, linkedPackages) => { if (linkedPackages.length === 0) return; const spinner = ora(`Replacing package links ${chalk.dim(`(${linkedPackages.join(',')})`)}`).start(); @@ -76,7 +74,7 @@ const replaceModules = async (libDir, appDir, linkedPackages, packageContent) => fs.writeFileSync(fullPath, newFileContent); } }); - addConsoleFlag(libDir, packageContent); + addConsoleFlag(libDir); spinner.succeed(); resolve(); From ee62e7aff80bb718fe50dba0b0ca6efa7324a6d1 Mon Sep 17 00:00:00 2001 From: nickofthyme Date: Thu, 20 May 2021 15:26:44 -0500 Subject: [PATCH 03/10] fix: update target and tsc options --- packages/link_kibana/main.js | 36 ++++++---- yarn.lock | 135 ++++++++++++++++++++++++++++++++++- 2 files changed, 154 insertions(+), 17 deletions(-) diff --git a/packages/link_kibana/main.js b/packages/link_kibana/main.js index c945e0c4cd..daf78252d7 100644 --- a/packages/link_kibana/main.js +++ b/packages/link_kibana/main.js @@ -141,13 +141,17 @@ to link charts with another application use ${chalk.cyan( await linkPackage(echDir, kibanaPath, packageName); cps.push( - await spawnWatch('yarn build:watch --preserveWatchOutput --pretty', packageName, { - cwd: echDir, - errorStr: 'error TS', - stopStr: 'Found 0 errors. Watching for file changes', - startStr: 'File change detected. Starting incremental compilation', - onUpdate: () => replaceModules(echDir, kibanaPath, linkedPackages), - }), + await spawnWatch( + 'yarn build:watch --preserveWatchOutput --pretty --noUnusedLocals false --target ES2018 --noUnusedLocals false ', + packageName, + { + cwd: echDir, + errorStr: 'error TS', + stopStr: 'Found 0 errors. Watching for file changes', + startStr: 'File change detected. Starting incremental compilation', + onUpdate: () => replaceModules(echDir, kibanaPath, linkedPackages), + }, + ), ); const kbnSharedPackage = path.join(kibanaPath, 'packages/kbn-ui-shared-deps'); @@ -182,13 +186,17 @@ to link charts with another application use ${chalk.cyan( if (action === 'Watch mode') { cps.push( - await spawnWatch('yarn build:watch --preserveWatchOutput', packageName, { - cwd: echDir, - errorStr: ': error TS', - stopStr: 'Found 0 errors. Watching for file changes', - startStr: 'File change detected. Starting incremental compilation', - onUpdate: () => replaceModules(echDir, kibanaPath, linkedPackages), - }), + await spawnWatch( + 'yarn build:watch --preserveWatchOutput --pretty --noUnusedLocals false --target ES2018', + packageName, + { + cwd: echDir, + errorStr: ': error TS', + stopStr: 'Found 0 errors. Watching for file changes', + startStr: 'File change detected. Starting incremental compilation', + onUpdate: () => replaceModules(echDir, kibanaPath, linkedPackages), + }, + ), ); const kbnSharedPackage = path.join(kibanaPath, 'packages/kbn-ui-shared-deps'); diff --git a/yarn.lock b/yarn.lock index 95fc47fa46..76d968ff5b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8768,7 +8768,7 @@ camel-case@^3.0.0: no-case "^2.2.0" upper-case "^1.1.1" -camel-case@^4.1.1: +camel-case@^4.1.1, camel-case@^4.1.2: version "4.1.2" resolved "https://registry.yarnpkg.com/camel-case/-/camel-case-4.1.2.tgz#9728072a954f805228225a6deea6b38461e1bd5a" integrity sha512-gxGWBrTT1JuMx6R+o5PTXMmUnhnVzLQ9SNutD4YqKtI6ap897t3tKECYla6gCWEkplXnlNybEkZg9GEGxKFCgw== @@ -8852,6 +8852,15 @@ canvas@^2.6.1: node-pre-gyp "^0.11.0" simple-get "^3.0.3" +capital-case@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/capital-case/-/capital-case-1.0.4.tgz#9d130292353c9249f6b00fa5852bee38a717e669" + integrity sha512-ds37W8CytHgwnhGGTi88pcPyR15qoNkOpYwmMMfnWqqWgESapLqvDx6huFjQ5vqWSn2Z06173XNA7LtMOeUh1A== + dependencies: + no-case "^3.0.4" + tslib "^2.0.3" + upper-case-first "^2.0.2" + capture-exit@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/capture-exit/-/capture-exit-2.0.0.tgz#fb953bfaebeb781f62898239dabb426d08a509a4" @@ -8928,6 +8937,32 @@ chalk@^3.0.0: ansi-styles "^4.1.0" supports-color "^7.1.0" +chalk@^4.1.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.1.tgz#c80b3fab28bf6371e6863325eee67e618b77e6ad" + integrity sha512-diHzdDKxcU+bAsUboHLPEDQiw0qEe0qd7SYUn3HgcFlWgbDcfLGswOHYeGrHKzG9z6UYf01d9VFMfZxPM1xZSg== + dependencies: + ansi-styles "^4.1.0" + supports-color "^7.1.0" + +change-case@^4.1.2: + version "4.1.2" + resolved "https://registry.yarnpkg.com/change-case/-/change-case-4.1.2.tgz#fedfc5f136045e2398c0410ee441f95704641e12" + integrity sha512-bSxY2ws9OtviILG1EiY5K7NNxkqg/JnRnFxLtKQ96JaviiIxi7djMrSd0ECT9AC+lttClmYwKw53BWpOMblo7A== + dependencies: + camel-case "^4.1.2" + capital-case "^1.0.4" + constant-case "^3.0.4" + dot-case "^3.0.4" + header-case "^2.0.4" + no-case "^3.0.4" + param-case "^3.0.4" + pascal-case "^3.1.2" + path-case "^3.0.4" + sentence-case "^3.0.4" + snake-case "^3.0.4" + tslib "^2.0.3" + char-regex@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/char-regex/-/char-regex-1.0.2.tgz#d744358226217f981ed58f479b1d6bcc29545dcf" @@ -9646,6 +9681,15 @@ consolidate@^0.15.1: dependencies: bluebird "^3.1.1" +constant-case@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/constant-case/-/constant-case-3.0.4.tgz#3b84a9aeaf4cf31ec45e6bf5de91bdfb0589faf1" + integrity sha512-I2hSBi7Vvs7BEuJDr5dDHfzb/Ruj3FyvFyh7KLilAjNQw3Be+xgqUBA2W6scVEcL0hL1dwPRtIqEPVUCKkSsyQ== + dependencies: + no-case "^3.0.4" + tslib "^2.0.3" + upper-case "^2.0.2" + constantinople@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/constantinople/-/constantinople-4.0.1.tgz#0def113fa0e4dc8de83331a5cf79c8b325213151" @@ -12919,6 +12963,18 @@ glob@^7.0.0, glob@^7.0.3, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4, gl once "^1.3.0" path-is-absolute "^1.0.0" +glob@^7.1.7: + version "7.1.7" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.7.tgz#3b193e9233f01d42d0b3f78294bbeeb418f94a90" + integrity sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ== + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.0.4" + once "^1.3.0" + path-is-absolute "^1.0.0" + global-dirs@^0.1.0, global-dirs@^0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/global-dirs/-/global-dirs-0.1.1.tgz#b319c0dd4607f353f3be9cca4c72fc148c49f445" @@ -13415,6 +13471,14 @@ he@^1.1.0, he@^1.2.0: resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f" integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw== +header-case@^2.0.4: + version "2.0.4" + resolved "https://registry.yarnpkg.com/header-case/-/header-case-2.0.4.tgz#5a42e63b55177349cf405beb8d775acabb92c063" + integrity sha512-H/vuk5TEEVZwrR0lp2zed9OCo1uAILMlx0JEMgC26rzyJJ3N1v6XkwHHXJQdR2doSjcGPM6OKPYoJgf0plJ11Q== + dependencies: + capital-case "^1.0.4" + tslib "^2.0.3" + highlight.js@^9.18.5: version "9.18.5" resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-9.18.5.tgz#d18a359867f378c138d6819edfc2a8acd5f29825" @@ -14089,6 +14153,25 @@ inquirer@^7.3.3: strip-ansi "^6.0.0" through "^2.3.6" +inquirer@^8.0.0: + version "8.0.0" + resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-8.0.0.tgz#957a46db1abcf0fdd2ab82deb7470e90afc7d0ac" + integrity sha512-ON8pEJPPCdyjxj+cxsYRe6XfCJepTxANdNnTebsTuQgXpRyZRRT9t4dJwjRubgmvn20CLSEnozRUayXyM9VTXA== + dependencies: + ansi-escapes "^4.2.1" + chalk "^4.1.0" + cli-cursor "^3.1.0" + cli-width "^3.0.0" + external-editor "^3.0.3" + figures "^3.0.0" + lodash "^4.17.21" + mute-stream "0.0.8" + run-async "^2.4.0" + rxjs "^6.6.6" + string-width "^4.1.0" + strip-ansi "^6.0.0" + through "^2.3.6" + internal-ip@^4.3.0: version "4.3.0" resolved "https://registry.yarnpkg.com/internal-ip/-/internal-ip-4.3.0.tgz#845452baad9d2ca3b69c635a137acb9a0dad0907" @@ -18481,7 +18564,7 @@ optionator@^0.9.1: type-check "^0.4.0" word-wrap "^1.2.3" -ora@^5.3.0: +ora@^5.3.0, ora@^5.4.0: version "5.4.0" resolved "https://registry.yarnpkg.com/ora/-/ora-5.4.0.tgz#42eda4855835b9cd14d33864c97a3c95a3f56bf4" integrity sha512-1StwyXQGoU6gdjYkyVcqOLnVlbKj+6yPNNOxJVgpt9t4eksKjiriiHuxktLYkgllwk+D6MbC4ihH84L1udRXPg== @@ -18747,7 +18830,7 @@ param-case@^2.1.1: dependencies: no-case "^2.2.0" -param-case@^3.0.3: +param-case@^3.0.3, param-case@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/param-case/-/param-case-3.0.4.tgz#7d17fe4aa12bde34d4a77d91acfb6219caad01c5" integrity sha512-RXlj7zCYokReqWpOPH9oYivUzLYZ5vAPIfEmCTNViosC78F8F0H9y7T7gG2M39ymgutxF5gcFEsyZQSph9Bp3A== @@ -18876,6 +18959,14 @@ path-browserify@0.0.1: resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-0.0.1.tgz#e6c4ddd7ed3aa27c68a20cc4e50e1a4ee83bbc4a" integrity sha512-BapA40NHICOS+USX9SN4tyhq+A2RrN/Ws5F0Z5aMHDp98Fl86lX8Oti8B7uN93L4Ifv4fHOEA+pQw87gmMO/lQ== +path-case@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/path-case/-/path-case-3.0.4.tgz#9168645334eb942658375c56f80b4c0cb5f82c6f" + integrity sha512-qO4qCFjXqVTrcbPt/hQfhTQ+VhFsqNKOPtytgNKkKxSoEp3XPUQ8ObFuePylOIok5gjn69ry8XiULxCwot3Wfg== + dependencies: + dot-case "^3.0.4" + tslib "^2.0.3" + path-dirname@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/path-dirname/-/path-dirname-1.0.2.tgz#cc33d24d525e099a5388c0336c6e32b9160609e0" @@ -21409,6 +21500,13 @@ rxjs@^6.4.0, rxjs@^6.6.0, rxjs@^6.6.3: dependencies: tslib "^1.9.0" +rxjs@^6.6.6: + version "6.6.7" + resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.6.7.tgz#90ac018acabf491bf65044235d5863c4dab804c9" + integrity sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ== + dependencies: + tslib "^1.9.0" + safe-buffer@5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853" @@ -21735,6 +21833,15 @@ send@0.17.1: range-parser "~1.2.1" statuses "~1.5.0" +sentence-case@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/sentence-case/-/sentence-case-3.0.4.tgz#3645a7b8c117c787fde8702056225bb62a45131f" + integrity sha512-8LS0JInaQMCRoQ7YUytAo/xUu5W2XnQxV2HI/6uM6U7CITS1RqPElr30V6uIqyMKM9lJGRVFy5/4CuzcixNYSg== + dependencies: + no-case "^3.0.4" + tslib "^2.0.3" + upper-case-first "^2.0.2" + serialize-javascript@^1.7.0: version "1.9.1" resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-1.9.1.tgz#cfc200aef77b600c47da9bb8149c943e798c2fdb" @@ -22033,6 +22140,14 @@ smart-buffer@^4.1.0: resolved "https://registry.yarnpkg.com/smart-buffer/-/smart-buffer-4.1.0.tgz#91605c25d91652f4661ea69ccf45f1b331ca21ba" integrity sha512-iVICrxOzCynf/SNaBQCw34eM9jROU/s5rzIhpOvzhzuYHfJR/DhZfDkXiZSgKXfgv26HT3Yni3AV/DGw0cGnnw== +snake-case@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/snake-case/-/snake-case-3.0.4.tgz#4f2bbd568e9935abdfd593f34c691dadb49c452c" + integrity sha512-LAOh4z89bGQvl9pFfNF8V146i7o7/CqFPbqzYgP+yYzDIDeS9HaNFtXABamRW+AQzEVODcvE79ljJ+8a9YSdMg== + dependencies: + dot-case "^3.0.4" + tslib "^2.0.3" + snapdragon-node@^2.0.1: version "2.1.1" resolved "https://registry.yarnpkg.com/snapdragon-node/-/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b" @@ -23933,11 +24048,25 @@ update-notifier@^2.2.0, update-notifier@^2.3.0, update-notifier@^2.5.0: semver-diff "^2.0.0" xdg-basedir "^3.0.0" +upper-case-first@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/upper-case-first/-/upper-case-first-2.0.2.tgz#992c3273f882abd19d1e02894cc147117f844324" + integrity sha512-514ppYHBaKwfJRK/pNC6c/OxfGa0obSnAl106u97Ed0I625Nin96KAjttZF6ZL3e1XLtphxnqrOi9iWgm+u+bg== + dependencies: + tslib "^2.0.3" + upper-case@^1.1.1: version "1.1.3" resolved "https://registry.yarnpkg.com/upper-case/-/upper-case-1.1.3.tgz#f6b4501c2ec4cdd26ba78be7222961de77621598" integrity sha1-9rRQHC7EzdJrp4vnIilh3ndiFZg= +upper-case@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/upper-case/-/upper-case-2.0.2.tgz#d89810823faab1df1549b7d97a76f8662bae6f7a" + integrity sha512-KgdgDGJt2TpuwBUIjgG6lzw2GWFRCW9Qkfkiv0DxqHHLYJHmtmdUIKcZd8rHgFSjopVTlw6ggzCm1b8MFQwikg== + dependencies: + tslib "^2.0.3" + uri-js@^4.2.2: version "4.4.1" resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.1.tgz#9b1a52595225859e55f669d928f88c6c57f2a77e" From 5b3d6e0ccd700182acfc8ace2a8746b351b5e41c Mon Sep 17 00:00:00 2001 From: nickofthyme Date: Mon, 24 May 2021 08:38:34 -0500 Subject: [PATCH 04/10] refactor: use fs.promise over promisify --- packages/link_kibana/utils.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/link_kibana/utils.js b/packages/link_kibana/utils.js index ae76964f5a..71e329bb0d 100644 --- a/packages/link_kibana/utils.js +++ b/packages/link_kibana/utils.js @@ -18,10 +18,9 @@ */ const { createHash } = require('crypto'); -const fs = require('fs'); +const fs = require('fs').promises; const os = require('os'); const path = require('path'); -const { promisify } = require('util'); const chalk = require('chalk'); const { snakeCase } = require('change-case'); @@ -30,7 +29,7 @@ const { exec } = require('./process_utils'); const exists = async (somePath) => { try { - await promisify(fs.access)(somePath, fs.constants.F_OK); + await fs.access(somePath, fs.constants.F_OK); return true; } catch (error) { if (error.code !== 'ENOENT') throw new Error(error); @@ -48,7 +47,7 @@ const getPackageInfo = async (pkgDir) => { const filePath = pkgDir.endsWith('/package.json') ? pkgDir : path.join(pkgDir, 'package.json'); try { - return JSON.parse(await promisify(fs.readFile)(filePath, 'utf8')); + return JSON.parse(await fs.readFile(filePath, 'utf8')); } catch (error) { if (error.code === 'ENOENT') { throw new Error(`Missing package.json file at ${filePath}`); @@ -59,7 +58,7 @@ const getPackageInfo = async (pkgDir) => { const createDir = async (dirPath) => { try { - await promisify(fs.mkdir)(dirPath); + await fs.mkdir(dirPath); } catch (error) { if (error.code !== 'EEXIST') throw new Error(error); } @@ -72,10 +71,10 @@ const createDir = async (dirPath) => { const getTempDir = async (cwd, packageName) => { const tempPrefix = `link_${snakeCase(packageName)}_`; const repoHash = hashValue(cwd); - const tempPkgDirName = (await promisify(fs.readdir)(os.tmpdir())).find((p) => p.startsWith(tempPrefix)); + const tempPkgDirName = (await fs.readdir(os.tmpdir())).find((p) => p.startsWith(tempPrefix)); const tempPkgDir = tempPkgDirName ? path.join(os.tmpdir(), tempPkgDirName) - : await promisify(fs.mkdtemp)(path.join(os.tmpdir(), tempPrefix)); + : await fs.mkdtemp(path.join(os.tmpdir(), tempPrefix)); const tempRepoDir = path.join(tempPkgDir, repoHash); await createDir(tempRepoDir); @@ -85,7 +84,7 @@ const getTempDir = async (cwd, packageName) => { const getLinkInfo = async (tempPath) => { try { const infoPath = path.join(tempPath, 'link.json'); - return JSON.parse(await promisify(fs.readFile)(infoPath, 'utf8')); + return JSON.parse(await fs.readFile(infoPath, 'utf8')); } catch { return { links: [] }; } @@ -95,7 +94,7 @@ const writeLinkInfo = async (tempPath, linkInfo) => { const infoPath = path.join(tempPath, 'link.json'); const data = JSON.stringify(linkInfo, null, 2); - await promisify(fs.writeFile)(infoPath, data, 'utf8'); + await fs.writeFile(infoPath, data, 'utf8'); }; const isLinked = (dirPath, linkPath) => { @@ -137,16 +136,16 @@ const linkPackage = async (target, linkPath, packageName) => { const linkPackagePath = path.join(linkPath, 'node_modules', packageName); const relativeLinkPath = path.relative(target, linkPackagePath); if (await exists(linkPackagePath)) { - await promisify(fs.rm)(linkPackagePath, { recursive: true, force: true }); + await fs.rm(linkPackagePath, { recursive: true, force: true }); } - await promisify(fs.symlink)(target, relativeLinkPath); + await fs.symlink(target, relativeLinkPath); }; const unlinkPackage = async (linkPath, packageName) => { const linkPackagePath = path.join(linkPath, 'node_modules', packageName); if (isLinked(linkPackagePath)) { - await promisify(fs.unlink)(linkPackagePath); + await fs.unlink(linkPackagePath); } return await restorePackage(linkPath, packageName); From 33fd4d217f91fb9ffec79d80fcc52e727fdad7a0 Mon Sep 17 00:00:00 2001 From: nickofthyme Date: Mon, 24 May 2021 15:05:12 -0500 Subject: [PATCH 05/10] fix: promise refactor issues --- packages/link_kibana/utils.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/link_kibana/utils.js b/packages/link_kibana/utils.js index 71e329bb0d..01c8f838cd 100644 --- a/packages/link_kibana/utils.js +++ b/packages/link_kibana/utils.js @@ -18,7 +18,7 @@ */ const { createHash } = require('crypto'); -const fs = require('fs').promises; +const fs = require('fs'); const os = require('os'); const path = require('path'); @@ -29,7 +29,7 @@ const { exec } = require('./process_utils'); const exists = async (somePath) => { try { - await fs.access(somePath, fs.constants.F_OK); + await fs.promises.access(somePath, fs.constants.F_OK); return true; } catch (error) { if (error.code !== 'ENOENT') throw new Error(error); @@ -47,7 +47,7 @@ const getPackageInfo = async (pkgDir) => { const filePath = pkgDir.endsWith('/package.json') ? pkgDir : path.join(pkgDir, 'package.json'); try { - return JSON.parse(await fs.readFile(filePath, 'utf8')); + return JSON.parse(await fs.promises.readFile(filePath, { encoding: 'utf8' })); } catch (error) { if (error.code === 'ENOENT') { throw new Error(`Missing package.json file at ${filePath}`); @@ -58,7 +58,7 @@ const getPackageInfo = async (pkgDir) => { const createDir = async (dirPath) => { try { - await fs.mkdir(dirPath); + await fs.promises.mkdir(dirPath); } catch (error) { if (error.code !== 'EEXIST') throw new Error(error); } @@ -71,10 +71,10 @@ const createDir = async (dirPath) => { const getTempDir = async (cwd, packageName) => { const tempPrefix = `link_${snakeCase(packageName)}_`; const repoHash = hashValue(cwd); - const tempPkgDirName = (await fs.readdir(os.tmpdir())).find((p) => p.startsWith(tempPrefix)); + const tempPkgDirName = (await fs.promises.readdir(os.tmpdir())).find((p) => p.startsWith(tempPrefix)); const tempPkgDir = tempPkgDirName ? path.join(os.tmpdir(), tempPkgDirName) - : await fs.mkdtemp(path.join(os.tmpdir(), tempPrefix)); + : await fs.promises.mkdtemp(path.join(os.tmpdir(), tempPrefix)); const tempRepoDir = path.join(tempPkgDir, repoHash); await createDir(tempRepoDir); @@ -84,7 +84,7 @@ const getTempDir = async (cwd, packageName) => { const getLinkInfo = async (tempPath) => { try { const infoPath = path.join(tempPath, 'link.json'); - return JSON.parse(await fs.readFile(infoPath, 'utf8')); + return JSON.parse(await fs.promises.readFile(infoPath, { encoding: 'utf8' })); } catch { return { links: [] }; } @@ -94,7 +94,7 @@ const writeLinkInfo = async (tempPath, linkInfo) => { const infoPath = path.join(tempPath, 'link.json'); const data = JSON.stringify(linkInfo, null, 2); - await fs.writeFile(infoPath, data, 'utf8'); + await fs.promises.writeFile(infoPath, data, { encoding: 'utf8' }); }; const isLinked = (dirPath, linkPath) => { @@ -136,16 +136,16 @@ const linkPackage = async (target, linkPath, packageName) => { const linkPackagePath = path.join(linkPath, 'node_modules', packageName); const relativeLinkPath = path.relative(target, linkPackagePath); if (await exists(linkPackagePath)) { - await fs.rm(linkPackagePath, { recursive: true, force: true }); + await fs.promises.rm(linkPackagePath, { recursive: true, force: true }); } - await fs.symlink(target, relativeLinkPath); + await fs.promises.symlink(target, relativeLinkPath); }; const unlinkPackage = async (linkPath, packageName) => { const linkPackagePath = path.join(linkPath, 'node_modules', packageName); if (isLinked(linkPackagePath)) { - await fs.unlink(linkPackagePath); + await fs.promises.unlink(linkPackagePath); } return await restorePackage(linkPath, packageName); From 6bc3aee906b40fb7d1c95b270aef4f95c11fc491 Mon Sep 17 00:00:00 2001 From: nickofthyme Date: Mon, 24 May 2021 14:52:38 -0500 Subject: [PATCH 06/10] chore: add debug flag and node version error handling --- .eslintrc.js | 1 + packages/link_kibana/main.js | 56 +++++++++++++++++---------- packages/link_kibana/process_utils.js | 37 ++++++++++++++++-- packages/link_kibana/utils.js | 7 ++-- 4 files changed, 73 insertions(+), 28 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index d3ac7ded69..70fc8a2cce 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -472,6 +472,7 @@ module.exports = { files: ['packages/link_kibana/**/*.js'], rules: { 'no-console': 0, + 'promise/no-promise-in-callback': 0, }, }, ], diff --git a/packages/link_kibana/main.js b/packages/link_kibana/main.js index daf78252d7..cd34ff3af6 100644 --- a/packages/link_kibana/main.js +++ b/packages/link_kibana/main.js @@ -52,6 +52,7 @@ module.exports = async () => { process.on('SIGINT', cleanExit); // catch ctrl-c process.on('SIGTERM', cleanExit); // catch kill + const debug = process.argv.includes('--debug'); const echDir = process.cwd(); const echPackageContent = await getPackageInfo(echDir); const packageName = echPackageContent.name; @@ -145,6 +146,7 @@ to link charts with another application use ${chalk.cyan( 'yarn build:watch --preserveWatchOutput --pretty --noUnusedLocals false --target ES2018 --noUnusedLocals false ', packageName, { + debug, cwd: echDir, errorStr: 'error TS', stopStr: 'Found 0 errors. Watching for file changes', @@ -157,6 +159,7 @@ to link charts with another application use ${chalk.cyan( const kbnSharedPackage = path.join(kibanaPath, 'packages/kbn-ui-shared-deps'); cps.push( await spawnWatch('yarn kbn:watch', '@kbn/ui-shared-dep', { + debug, cwd: kbnSharedPackage, errorStr: 'ERROR', stopStr: 'webpack completed', @@ -190,6 +193,7 @@ to link charts with another application use ${chalk.cyan( 'yarn build:watch --preserveWatchOutput --pretty --noUnusedLocals false --target ES2018', packageName, { + debug, cwd: echDir, errorStr: ': error TS', stopStr: 'Found 0 errors. Watching for file changes', @@ -202,6 +206,7 @@ to link charts with another application use ${chalk.cyan( const kbnSharedPackage = path.join(kibanaPath, 'packages/kbn-ui-shared-deps'); cps.push( await spawnWatch('yarn kbn:watch', '@kbn/ui-shared-dep', { + debug, cwd: kbnSharedPackage, errorStr: 'ERROR', stopStr: 'webpack completed', @@ -212,31 +217,40 @@ to link charts with another application use ${chalk.cyan( return; } - await exec('yarn build', `Restoring build ${chalk.dim(packageName)}`, { cwd: echDir, errorStr: ': error TS' }); - const chartsFileRestored = await unlinkPackage(linkInfo.path, packageName); + try { + await exec('yarn build', `Restoring build ${chalk.dim(packageName)}`, { + debug, + cwd: echDir, + errorStr: ': error TS', + }); + const chartsFileRestored = await unlinkPackage(linkInfo.path, packageName, debug); - await writeLinkInfo(tempDir, {}); + await writeLinkInfo(tempDir, {}); - if (chartsFileRestored) { - try { - const kbnSharedPackage = path.join(kibanaPath, 'packages/kbn-ui-shared-deps'); - await exec('yarn build --dev', `Restoring build ${chalk.dim('@kbn/ui-shared-dep')}`, { - errorStr: 'ERROR', - cwd: kbnSharedPackage, - }); + if (chartsFileRestored) { + try { + const kbnSharedPackage = path.join(kibanaPath, 'packages/kbn-ui-shared-deps'); + await exec('yarn build --dev', `Restoring build ${chalk.dim('@kbn/ui-shared-dep')}`, { + debug, + errorStr: 'ERROR', + cwd: kbnSharedPackage, + }); - console.log(` - Unlink Successful. Kibana has been restored to the pre-linked state. - Please refresh kibana to see restored state.`); - return; - } catch { - // fallthrough + console.log(` + Unlink Successful. Kibana has been restored to the pre-linked state. + Please refresh kibana to see restored state.`); + return; + } catch { + // fallthrough + } } - } - console.log(` -Unlink Complete. Kibana was ${chalk.underline('not')} restored to the pre-linked state. Please run ${chalk.cyan( - 'yarn kbn bootstrap --no-cache', - )}`); + console.log(` + Unlink Complete. Kibana was ${chalk.underline('not')} restored to the pre-linked state. Please run ${chalk.cyan( + 'yarn kbn bootstrap --no-cache', + )}`); + } catch { + console.log(`Unlink Failed. Please fix issues above or run with ${chalk.underline('--debug')} flag.`); + } } }; diff --git a/packages/link_kibana/process_utils.js b/packages/link_kibana/process_utils.js index 22b6d87ce2..95fdf4cb0e 100644 --- a/packages/link_kibana/process_utils.js +++ b/packages/link_kibana/process_utils.js @@ -39,16 +39,39 @@ const parseBuffer = (buf) => { ); }; +const debugLog = (...args) => console.log(...['\nDEBUG: ', ...args].map((a) => chalk.blue(a))); + const printErrorMsg = () => { console.log(chalk.redBright.bold('\n An Error occured, please resolve the issue(s) below:\n')); }; -const exec = async (command, message, { cwd, errorMsg, errorStr } = {}) => { +const printNodeVersionError = (error, cwd) => { + if (error.toString().includes('The engine "node" is incompatible with this module')) { + const [, newVersion] = /Expected version "(.+?)"/.exec(error.toString()) ?? []; + console.log(`You must update your node version, please run the commands below and try again + +cd ${cwd} +nvm install ${newVersion} && nvm use + +cd ${process.cwd()} +yarn link:kibana + +If you don't use nvm please install the expected node version. +`); + } +}; + +const exec = async (command, message, { cwd, errorMsg, errorStr, debug } = {}) => { const spinner = ora(message).start(); - await new Promise((resolve) => { + await new Promise((resolve, reject) => { childProcess.exec(command, { cwd, timeout: 2 * 60 * 1000 }, (error, stdoutBuf, stderrBuf) => { const stdout = parseBuffer(stdoutBuf); const stderr = parseBuffer(stderrBuf); + if (debug) { + if (stdout) debugLog('stdout:\n\n', stdout); + if (stderr) debugLog('stderr:\n\n', stderr); + if (error) debugLog('error:\n\n', error); + } if (stdout && !spinner.isSpinning) { spinner.start(); @@ -75,6 +98,9 @@ const exec = async (command, message, { cwd, errorMsg, errorStr } = {}) => { if (error) { spinner.fail(errorMsg || error); + printError(error); + printNodeVersionError(error, cwd); + reject(error); return; } @@ -84,7 +110,7 @@ const exec = async (command, message, { cwd, errorMsg, errorStr } = {}) => { }); }; -const spawnWatch = (command, packageName, { cwd, startStr, stopStr, onUpdate, errorStr } = {}) => +const spawnWatch = (command, packageName, { cwd, startStr, stopStr, onUpdate, errorStr, debug } = {}) => new Promise((resolve, reject) => { console.log(`Starting build of ${chalk.cyan.bold(packageName)} in detatched watch mode`); let spinner = ora(`Building initial files ${chalk.dim(packageName)}`).start(); @@ -98,6 +124,7 @@ const spawnWatch = (command, packageName, { cwd, startStr, stopStr, onUpdate, er let hasError = false; cp.stdout.on('data', (dataBuffer) => { const stdout = parseBuffer(dataBuffer); + if (debug && stdout) debugLog('stdout:\n\n', stdout); if (startStr && !spinner.isSpinning && stdout.includes(startStr)) { spinner = ora(`Building changed files ${chalk.dim(packageName)}`).start(); return; @@ -126,6 +153,7 @@ const spawnWatch = (command, packageName, { cwd, startStr, stopStr, onUpdate, er if (errorStr) { cp.stderr.on('data', (dataBuffer) => { const stderr = parseBuffer(dataBuffer); + if (debug && stderr) debugLog('stderr:\n\n', stderr); if (stderr.includes(errorStr)) { if (!hasError) { spinner.fail(); @@ -141,9 +169,10 @@ const spawnWatch = (command, packageName, { cwd, startStr, stopStr, onUpdate, er } cp.on('error', (error) => { + printError(error); spinner.fail(error); + printNodeVersionError(error, cwd); reject(error); - throw new Error(error); }); return cp; diff --git a/packages/link_kibana/utils.js b/packages/link_kibana/utils.js index 01c8f838cd..0af1298daf 100644 --- a/packages/link_kibana/utils.js +++ b/packages/link_kibana/utils.js @@ -115,13 +115,14 @@ const isLinked = (dirPath, linkPath) => { return true; }; -const restorePackage = async (appDir, packageName) => { +const restorePackage = async (appDir, packageName, debug) => { try { const errorMsg = `Unable to restore ${chalk.cyan(packageName)} package in ${chalk.cyan(path.basename(appDir))}`; await exec( `yarn add ${packageName} --force --exact`, `Restoring ${chalk.cyan(packageName)} in ${chalk.cyan(path.basename(appDir))}`, { + debug, cwd: appDir, errorMsg, }, @@ -141,14 +142,14 @@ const linkPackage = async (target, linkPath, packageName) => { await fs.promises.symlink(target, relativeLinkPath); }; -const unlinkPackage = async (linkPath, packageName) => { +const unlinkPackage = async (linkPath, packageName, debug) => { const linkPackagePath = path.join(linkPath, 'node_modules', packageName); if (isLinked(linkPackagePath)) { await fs.promises.unlink(linkPackagePath); } - return await restorePackage(linkPath, packageName); + return await restorePackage(linkPath, packageName, debug); }; module.exports = { From 2a614b8b3c1c0c53ee6beaca8b865dd3bc228ff3 Mon Sep 17 00:00:00 2001 From: nickofthyme Date: Mon, 24 May 2021 16:26:55 -0500 Subject: [PATCH 07/10] fix: reject promise for stderrs --- packages/link_kibana/process_utils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/link_kibana/process_utils.js b/packages/link_kibana/process_utils.js index 95fdf4cb0e..890916ec44 100644 --- a/packages/link_kibana/process_utils.js +++ b/packages/link_kibana/process_utils.js @@ -92,6 +92,7 @@ const exec = async (command, message, { cwd, errorMsg, errorStr, debug } = {}) = spinner.fail(); printErrorMsg(); errors.forEach(printError); + reject(); return; } } From 409e5c674bfca686daf2aca4dd2f22b9bbae49da Mon Sep 17 00:00:00 2001 From: nickofthyme Date: Wed, 26 May 2021 11:05:54 -0500 Subject: [PATCH 08/10] chore: add last updated log --- packages/link_kibana/replace_modules.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/link_kibana/replace_modules.js b/packages/link_kibana/replace_modules.js index eda1ec551d..0707c073fc 100644 --- a/packages/link_kibana/replace_modules.js +++ b/packages/link_kibana/replace_modules.js @@ -35,7 +35,8 @@ const addConsoleFlag = (dirPath) => { console.log( '\\n%cLinked @elastic/charts!', 'font-weight: bold; font-size: 30px;color: #f04d9a; text-shadow: 2px 2px 0 #14abf5 , 4px 4px 0 #fec709 , 6px 6px 0 #00c1b4', - '\\n\\ndir:', '${dirPath}\\n\\n' + '\\n\\nlast updated ' + require('moment')(${Date.now()}).fromNow(), + '\\ndir:', '${dirPath}\\n\\n', ); `; fs.appendFileSync(filePath, appendContent); From 55f4b5a9e9f38c4e730f9c04d2d21ef537364846 Mon Sep 17 00:00:00 2001 From: nickofthyme Date: Wed, 26 May 2021 12:21:05 -0500 Subject: [PATCH 09/10] fix: build order before linking --- packages/link_kibana/main.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/link_kibana/main.js b/packages/link_kibana/main.js index cd34ff3af6..b062b3bf66 100644 --- a/packages/link_kibana/main.js +++ b/packages/link_kibana/main.js @@ -139,8 +139,6 @@ to link charts with another application use ${chalk.cyan( return; } - await linkPackage(echDir, kibanaPath, packageName); - cps.push( await spawnWatch( 'yarn build:watch --preserveWatchOutput --pretty --noUnusedLocals false --target ES2018 --noUnusedLocals false ', @@ -156,6 +154,9 @@ to link charts with another application use ${chalk.cyan( ), ); + // must be run after first build so all assests are visibile to kibana + await linkPackage(echDir, kibanaPath, packageName); + const kbnSharedPackage = path.join(kibanaPath, 'packages/kbn-ui-shared-deps'); cps.push( await spawnWatch('yarn kbn:watch', '@kbn/ui-shared-dep', { From 5a7ee10fb6f6c1d76634f14954b2518e8c1e2f95 Mon Sep 17 00:00:00 2001 From: nickofthyme Date: Thu, 27 May 2021 17:33:08 -0500 Subject: [PATCH 10/10] fix: typo and last updated timestamp --- packages/link_kibana/main.js | 2 +- packages/link_kibana/replace_modules.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/link_kibana/main.js b/packages/link_kibana/main.js index b062b3bf66..473acae889 100644 --- a/packages/link_kibana/main.js +++ b/packages/link_kibana/main.js @@ -77,7 +77,7 @@ module.exports = async () => { if (action === 'Link') { const { appLinkRelativePath } = await inquirer.prompt({ name: 'appLinkRelativePath', - message: 'Enter path to applitcation directory to link', + message: 'Enter path to application directory to link', default: '../kibana', }); const kibanaPath = path.resolve(echDir, appLinkRelativePath); diff --git a/packages/link_kibana/replace_modules.js b/packages/link_kibana/replace_modules.js index 0707c073fc..8f355cec40 100644 --- a/packages/link_kibana/replace_modules.js +++ b/packages/link_kibana/replace_modules.js @@ -28,9 +28,8 @@ const addConsoleFlag = (dirPath) => { const filePath = path.join(dirPath, 'dist/index.js'); try { const existingContent = fs.readFileSync(filePath, 'utf8'); + const appendContent = ` - if (!existingContent.includes('LINKED CONSOLE FLAG')) { - const appendContent = ` // LINKED CONSOLE FLAG console.log( '\\n%cLinked @elastic/charts!', @@ -39,6 +38,11 @@ console.log( '\\ndir:', '${dirPath}\\n\\n', ); `; + + if (existingContent.includes('// LINKED CONSOLE FLAG')) { + const newContent = existingContent.replace(/(\n)*\/\/ linked console flag(.|\n)+$/gi, appendContent); + fs.writeFileSync(filePath, newContent); + } else { fs.appendFileSync(filePath, appendContent); } } catch {