chore(NA): ensure scripts run with --preserve-symlinks (#94046) (#94636)

* chore(NA): ensure scripts run with --preserve-symlinks

* chore(NA): run webpack configs with symlinks: false

* chore(NA): fix pkg json load on kbn test

* chore(NA): add script into setup node env

* chore(NA): fix kbn test for relative improt

* chore(NA): fix change on docs

* chore(NA): move ensure node preserve symlinks into setup node env

* chore(NA): update changed docs

* chore(NA): update jest unit test

* chore(NA): fix wrapper script exit code

* chore(NA): updated generated plugin list docs

* fix(NA): make functional test runner use kbn utils repo_root

* chore(NA): fix eslint imports

* chore(NA): missing react correct config on eslint package

* chore(NA): use correct value to make test pass locally

* chore(NA): fix jest tests

* chore(NA): try remove extra preserve symlinks

* chore(NA): fix windows environment

* chore(NA): fix kbn-optimizer to run with preserve-symlinks

* chore(NA): fix integration jest test for kbn/optimizer

* chore(NA): remove require.resolve from eslintrc.js

* chore(NA): avoid load json file

* chore(NA): move kbn/utils import into kbn/dev-utils

* chore(NA): use correct dependencies on eslint config package

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Tiago Costa 2021-03-15 22:57:30 +00:00 committed by GitHub
parent 2e917c9ef5
commit e3c70f51fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 118 additions and 22 deletions

View file

@ -16,5 +16,8 @@
"bugs": {
"url": "https://github.com/elastic/kibana/tree/master/packages/elastic-eslint-config-kibana"
},
"homepage": "https://github.com/elastic/kibana/tree/master/packages/elastic-eslint-config-kibana"
"homepage": "https://github.com/elastic/kibana/tree/master/packages/elastic-eslint-config-kibana",
"dependencies": {
"@kbn/dev-utils": "link:../kbn-dev-utils"
}
}

View file

@ -1,5 +1,5 @@
const semver = require('semver')
const PKG = require('../../package.json')
const semver = require('semver');
const { kibanaPackageJson: PKG } = require('@kbn/dev-utils');
module.exports = {
plugins: [

View file

@ -4,7 +4,7 @@
// as this package was moved from typescript-eslint-parser to @typescript-eslint/parser
const semver = require('semver');
const PKG = require('../../package.json');
const { kibanaPackageJson: PKG } = require('@kbn/dev-utils');
const eslintConfigPrettierTypescriptEslintRules = require('eslint-config-prettier/@typescript-eslint').rules;

View file

@ -6,6 +6,7 @@
* Side Public License, v 1.
*/
import Fs from 'fs';
import Path from 'path';
import normalizePath from 'normalize-path';
@ -48,7 +49,7 @@ NOTE:
node scripts/build_plugin_list_docs
You can update the template within ${normalizePath(
Path.relative(REPO_ROOT, Path.resolve(__dirname, __filename))
Path.relative(REPO_ROOT, Fs.realpathSync(Path.resolve(__dirname, __filename)))
)}
////

View file

@ -150,9 +150,9 @@ it('builds expected bundles, saves bundle counts to metadata', async () => {
expect(bar.cache.getReferencedFiles()).toMatchInlineSnapshot(`
Array [
<absolute path>/node_modules/@kbn/optimizer/postcss.config.js,
<absolute path>/node_modules/css-loader/package.json,
<absolute path>/node_modules/style-loader/package.json,
<absolute path>/packages/kbn-optimizer/postcss.config.js,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/bar/kibana.json,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/bar/public/index.scss,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/bar/public/index.ts,

View file

@ -63,6 +63,7 @@ function usingWorkerProc<T>(
(): ProcResource => {
const proc = execa.node(require.resolve('../worker/run_worker'), [], {
nodeOptions: [
...process.execArgv,
...(inspectFlag && config.inspectWorkers
? [`${inspectFlag}=${inspectPortCounter++}`]
: []),

View file

@ -220,6 +220,7 @@ export function getWebpackConfig(bundle: Bundle, bundleRefs: BundleRefs, worker:
alias: {
core_app_image_assets: Path.resolve(worker.repoRoot, 'src/core/public/core_app/images'),
},
symlinks: false,
},
performance: {

View file

@ -23,6 +23,7 @@ module.exports = {
resolve: {
extensions: ['.ts', '.js'],
symlinks: false,
},
module: {

View file

@ -6,6 +6,7 @@
* Side Public License, v 1.
*/
import { REPO_ROOT } from '@kbn/utils';
import { resolve, relative } from 'path';
// resolve() treats relative paths as relative to process.cwd(),
@ -16,7 +17,7 @@ function resolveRelative(path) {
export const KIBANA_EXEC = 'node';
export const KIBANA_EXEC_PATH = resolveRelative('scripts/kibana');
export const KIBANA_ROOT = resolve(__dirname, '../../../../../');
export const KIBANA_ROOT = REPO_ROOT;
export const KIBANA_FTR_SCRIPT = resolve(KIBANA_ROOT, 'scripts/functional_test_runner');
export const PROJECT_ROOT = resolve(__dirname, '../../../../../../');
export const FUNCTIONAL_CONFIG_PATH = resolve(KIBANA_ROOT, 'test/functional/config');

View file

@ -62,11 +62,15 @@ function collectCliArgs(config, { installDir, extraKbnOpts }) {
const buildArgs = config.get('kbnTestServer.buildArgs') || [];
const sourceArgs = config.get('kbnTestServer.sourceArgs') || [];
const serverArgs = config.get('kbnTestServer.serverArgs') || [];
const execArgv = process.execArgv || [];
return pipe(
serverArgs,
(args) => (installDir ? args.filter((a) => a !== '--oss') : args),
(args) => (installDir ? [...buildArgs, ...args] : [KIBANA_EXEC_PATH, ...sourceArgs, ...args]),
(args) =>
installDir
? [...buildArgs, ...args]
: [...execArgv, KIBANA_EXEC_PATH, ...sourceArgs, ...args],
(args) => args.concat(extraKbnOpts || [])
);
}

View file

@ -6,8 +6,8 @@
* Side Public License, v 1.
*/
import { kibanaPackageJson as pkg } from '@kbn/dev-utils';
import url, { format as formatUrl } from 'url';
import pkg from '../../../../package.json';
import { adminTestUser } from '../kbn';
export const esTestConfig = new (class EsTestConfig {

View file

@ -6,6 +6,7 @@
* Side Public License, v 1.
*/
import { REPO_ROOT } from '@kbn/utils';
import { dirname, relative } from 'path';
import { writeFileSync, mkdirSync } from 'fs';
import { inspect } from 'util';
@ -21,7 +22,7 @@ const dateNow = Date.now.bind(Date);
export function setupJUnitReportGeneration(runner, options = {}) {
const {
reportName = 'Unnamed Mocha Tests',
rootDirectory = dirname(require.resolve('../../../../package.json')),
rootDirectory = REPO_ROOT,
getTestMetadata = () => ({}),
} = options;

View file

@ -101,6 +101,7 @@ exports.getWebpackConfig = ({ dev = false } = {}) => ({
moment: MOMENT_SRC,
},
extensions: ['.js', '.ts'],
symlinks: false,
},
optimization: {

View file

@ -7,7 +7,6 @@
*/
import Path from 'path';
import Fs from 'fs';
import loadJsonFile from 'load-json-file';
@ -31,7 +30,7 @@ const findKibanaPackageJson = () => {
// search for the kibana directory, since this file is moved around it might
// not be where we think but should always be a relatively close parent
// of this directory
const startDir = Fs.realpathSync(__dirname);
const startDir = __dirname;
const { root: rootDir } = Path.parse(startDir);
let cursor = startDir;
while (true) {

View file

@ -6,6 +6,7 @@
* Side Public License, v 1.
*/
require('../src/setup_node_env/ensure_node_preserve_symlinks');
require('@kbn/optimizer').runKbnOptimizerCli({
defaultLimitsPath: require.resolve('../packages/kbn-optimizer/limits.yml'),
});

View file

@ -6,4 +6,5 @@
* Side Public License, v 1.
*/
require('../src/setup_node_env/ensure_node_preserve_symlinks');
require('@kbn/test').runJest();

View file

@ -6,6 +6,7 @@
* Side Public License, v 1.
*/
require('../src/setup_node_env/ensure_node_preserve_symlinks');
process.argv.push('--runInBand');
require('@kbn/test').runJest('jest.config.integration.js');

View file

@ -6,5 +6,6 @@
* Side Public License, v 1.
*/
require('../src/setup_node_env/ensure_node_preserve_symlinks');
require('../src/setup_node_env/node_version_validator');
require('../packages/kbn-pm/cli');

View file

@ -6,5 +6,6 @@
* Side Public License, v 1.
*/
require('../src/setup_node_env/ensure_node_preserve_symlinks');
require('@kbn/optimizer').registerNodeAutoTranspilation();
require('../src/dev/run_precommit_hook');

View file

@ -6,6 +6,8 @@
* Side Public License, v 1.
*/
require('../src/setup_node_env/ensure_node_preserve_symlinks');
var execFileSync = require('child_process').execFileSync;
var path = require('path');
var syncGlob = require('glob').sync;

View file

@ -122,7 +122,10 @@ describe('#run$', () => {
"ELASTIC_APM_SERVICE_NAME": "kibana",
"isDevCliChild": "true",
},
"nodeOptions": Array [],
"nodeOptions": Array [
"--preserve-symlinks-main",
"--preserve-symlinks",
],
"stdio": "pipe",
},
],

View file

@ -0,0 +1,63 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
(function () {
var cp = require('child_process');
var preserveSymlinksOption = '--preserve-symlinks';
var preserveSymlinksMainOption = '--preserve-symlinks-main';
var nodeOptions = (process && process.env && process.env.NODE_OPTIONS) || [];
var nodeExecArgv = (process && process.execArgv) || [];
var isPreserveSymlinksPresent =
nodeOptions.includes(preserveSymlinksOption) || nodeExecArgv.includes(preserveSymlinksOption);
var isPreserveSymlinksMainPresent =
nodeOptions.includes(preserveSymlinksMainOption) ||
nodeExecArgv.includes(preserveSymlinksMainOption);
if (isPreserveSymlinksPresent && isPreserveSymlinksMainPresent) {
return;
}
var nodeArgv = (process && process.argv) || [];
var isFirstArgNode = nodeArgv.length > 0 && nodeArgv[0].includes('node') ? nodeArgv[0] : null;
if (!isFirstArgNode) {
return;
}
var missingNodeArgs = [];
if (!isPreserveSymlinksMainPresent) {
missingNodeArgs.push(preserveSymlinksMainOption);
}
if (!isPreserveSymlinksPresent) {
missingNodeArgs.push(preserveSymlinksOption);
}
var nodeArgs = nodeExecArgv.concat(missingNodeArgs);
var restArgs = nodeArgv.length >= 2 ? nodeArgv.slice(1, nodeArgv.length) : [];
var getExitCodeFromSpawnResult = function (spawnResult) {
if (spawnResult.status !== null) {
return spawnResult.status;
}
if (spawnResult.signal !== null) {
return 128 + spawnResult.signal;
}
if (spawnResult.error) {
return 1;
}
return 0;
};
var spawnResult = cp.spawnSync(nodeArgv[0], nodeArgs.concat(restArgs), { stdio: 'inherit' });
process.exit(getExitCodeFromSpawnResult(spawnResult));
})();

View file

@ -6,6 +6,8 @@
* Side Public License, v 1.
*/
require('./ensure_node_preserve_symlinks');
// The following require statements MUST be executed before any others - BEGIN
require('./exit_on_warning');
require('./harden');

View file

@ -36,6 +36,8 @@
// Resolve modules in the same way as Node.js. Aka make `require` works the
// same in TypeScript as it does in Node.js.
"moduleResolution": "node",
// Do not resolve the real path of symlinks
"preserveSymlinks": true,
// "resolveJsonModule" allows for importing, extracting types from and generating .json files.
"resolveJsonModule": true,
// Disallow inconsistently-cased references to the same file.

View file

@ -9,9 +9,7 @@
"kbn": "node ../scripts/kbn",
"kbn:bootstrap": "node plugins/canvas/scripts/storybook --clean",
"start": "node ../scripts/kibana --dev",
"build": "../node_modules/.bin/gulp build",
"testonly": "echo 'Deprecated, use `yarn test`'",
"test": "../node_modules/.bin/gulp test",
"build": "node --preserve-symlinks ../node_modules/.bin/gulp build",
"test:jest": "node ../scripts/jest"
},
"kibana": {

View file

@ -8,6 +8,7 @@
module.exports = {
resolve: {
extensions: ['.ts', '.js'],
symlinks: false,
},
node: { fs: 'empty', child_process: 'empty', readline: 'empty' },
module: {

View file

@ -43,6 +43,7 @@ module.exports = {
core_app_image_assets: path.resolve(KIBANA_ROOT, 'src/core/public/core_app/images'),
},
extensions: ['.js', '.json', '.ts', '.tsx', '.scss'],
symlinks: false,
},
module: {
rules: [

View file

@ -190,6 +190,7 @@ module.exports = async ({ config: storybookConfig }) => {
'../tasks/mocks/uiAbsoluteToParsedUrl'
),
},
symlinks: false,
},
};

View file

@ -82,6 +82,7 @@ module.exports = {
alias: {
ui: path.resolve(KIBANA_ROOT, 'src/legacy/ui/public'),
},
symlinks: false,
},
module: {
rules: [

View file

@ -94,12 +94,16 @@ async function copySourceAndBabelify() {
}
async function buildCanvasShareableRuntime() {
await execa(process.execPath, ['plugins/canvas/scripts/shareable_runtime'], {
cwd: XPACK_DIR,
stdio: ['ignore', 'inherit', 'inherit'],
// @ts-ignore Incorrect @types - execa supports `buffer`
buffer: false,
});
await execa(
process.execPath,
['--preserve-symlinks', 'plugins/canvas/scripts/shareable_runtime'],
{
cwd: XPACK_DIR,
stdio: ['ignore', 'inherit', 'inherit'],
// @ts-ignore Incorrect @types - execa supports `buffer`
buffer: false,
}
);
}
async function generateNoticeText() {