Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
[kbn/es] use a basic build process (elastic#78090)
Browse files Browse the repository at this point in the history
Co-authored-by: spalger <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
3 people committed Sep 28, 2020
1 parent b2bc2c2 commit f79b2e7
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 65 deletions.
11 changes: 10 additions & 1 deletion packages/kbn-es/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"name": "@kbn/es",
"main": "./src/index.js",
"main": "./target/index.js",
"version": "1.0.0",
"license": "Apache-2.0",
"private": true,
"scripts": {
"kbn:bootstrap": "node scripts/build",
"kbn:watch": "node scripts/build --watch"
},
"dependencies": {
"@elastic/elasticsearch": "7.9.0-rc.1",
"@kbn/dev-utils": "1.0.0",
Expand All @@ -19,5 +23,10 @@
"tar-fs": "^2.1.0",
"tree-kill": "^1.2.2",
"yauzl": "^2.10.0"
},
"devDependencies": {
"@kbn/babel-preset": "1.0.0",
"@babel/cli": "^7.10.5",
"del": "^5.1.0"
}
}
71 changes: 71 additions & 0 deletions packages/kbn-es/scripts/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* 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 { resolve } = require('path');

const del = require('del');
const { run, withProcRunner } = require('@kbn/dev-utils');

const ROOT_DIR = resolve(__dirname, '..');
const BUILD_DIR = resolve(ROOT_DIR, 'target');

run(
async ({ log, flags }) => {
await withProcRunner(log, async (proc) => {
log.info('Deleting old output');
await del(BUILD_DIR);

const cwd = ROOT_DIR;

log.info(`Starting babel${flags.watch ? ' in watch mode' : ''}`);
await proc.run(`babel`, {
cmd: 'babel',
args: [
'src',
'--no-babelrc',
'--presets',
require.resolve('@kbn/babel-preset/node_preset'),
'--extensions',
'.ts,.js',
'--copy-files',
'--out-dir',
BUILD_DIR,
...(flags.watch ? ['--watch'] : ['--quiet']),
...(!flags['source-maps'] || !!process.env.CODE_COVERAGE
? []
: ['--source-maps', 'inline']),
],
wait: true,
cwd,
});

log.success('Complete');
});
},
{
description: 'Simple build tool for @kbn/es package',
flags: {
boolean: ['watch', 'source-maps'],
help: `
--watch Run in watch mode
--source-maps Include sourcemaps
`,
},
}
);
104 changes: 53 additions & 51 deletions packages/kbn-es/src/integration_tests/__fixtures__/es_bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,65 +25,67 @@ const { exitCode, start, ssl } = JSON.parse(process.argv[2]);
const { createServer } = ssl ? require('https') : require('http');
const { ES_KEY_PATH, ES_CERT_PATH } = require('@kbn/dev-utils');

process.exitCode = exitCode;
(function main() {
process.exitCode = exitCode;

if (!start) {
return;
}
if (!start) {
return;
}

let serverUrl;
const server = createServer(
{
// Note: the integration uses the ES_P12_PATH, but that keystore contains
// the same key/cert as ES_KEY_PATH and ES_CERT_PATH
key: ssl ? fs.readFileSync(ES_KEY_PATH) : undefined,
cert: ssl ? fs.readFileSync(ES_CERT_PATH) : undefined,
},
(req, res) => {
const url = new URL(req.url, serverUrl);
const send = (code, body) => {
res.writeHead(code, { 'content-type': 'application/json' });
res.end(JSON.stringify(body));
};

let serverUrl;
const server = createServer(
{
// Note: the integration uses the ES_P12_PATH, but that keystore contains
// the same key/cert as ES_KEY_PATH and ES_CERT_PATH
key: ssl ? fs.readFileSync(ES_KEY_PATH) : undefined,
cert: ssl ? fs.readFileSync(ES_CERT_PATH) : undefined,
},
(req, res) => {
const url = new URL(req.url, serverUrl);
const send = (code, body) => {
res.writeHead(code, { 'content-type': 'application/json' });
res.end(JSON.stringify(body));
};
if (url.pathname === '/_xpack') {
return send(400, {
error: {
reason: 'foo bar',
},
});
}

if (url.pathname === '/_xpack') {
return send(400, {
return send(404, {
error: {
reason: 'foo bar',
reason: 'not found',
},
});
}
);

return send(404, {
error: {
reason: 'not found',
},
});
}
);

// setup server auto close after 1 second of silence
let serverCloseTimer;
const delayServerClose = () => {
clearTimeout(serverCloseTimer);
serverCloseTimer = setTimeout(() => server.close(), 1000);
};
server.on('request', delayServerClose);
server.on('listening', delayServerClose);
// setup server auto close after 1 second of silence
let serverCloseTimer;
const delayServerClose = () => {
clearTimeout(serverCloseTimer);
serverCloseTimer = setTimeout(() => server.close(), 1000);
};
server.on('request', delayServerClose);
server.on('listening', delayServerClose);

server.listen(0, '127.0.0.1', function () {
const { port, address: hostname } = server.address();
serverUrl = new URL(
formatUrl({
protocol: 'http:',
port,
hostname,
})
);
server.listen(0, '127.0.0.1', function () {
const { port, address: hostname } = server.address();
serverUrl = new URL(
formatUrl({
protocol: 'http:',
port,
hostname,
})
);

console.log(
`[o.e.h.AbstractHttpServerTransport] [computer] publish_address {127.0.0.1:${port}}, bound_addresses {[::1]:${port}}, {127.0.0.1:${port}}`
);
console.log(
`[o.e.h.AbstractHttpServerTransport] [computer] publish_address {127.0.0.1:${port}}, bound_addresses {[::1]:${port}}, {127.0.0.1:${port}}`
);

console.log('started');
});
console.log('started');
});
})();
2 changes: 1 addition & 1 deletion scripts/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

require('../src/setup_node_env');
require('../src/setup_node_env/prebuilt_dev_only_entry');

var resolve = require('path').resolve;
var pkg = require('../package.json');
Expand Down
19 changes: 7 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@


"@babel/cli@^7.10.5":
version "7.10.5"
resolved "https://registry.yarnpkg.com/@babel/cli/-/cli-7.10.5.tgz#57df2987c8cf89d0fc7d4b157ec59d7619f1b77a"
integrity sha512-j9H9qSf3kLdM0Ao3aGPbGZ73mEA9XazuupcS6cDGWuiyAcANoguhP0r2Lx32H5JGw4sSSoHG3x/mxVnHgvOoyA==
version "7.11.6"
resolved "https://registry.yarnpkg.com/@babel/cli/-/cli-7.11.6.tgz#1fcbe61c2a6900c3539c06ee58901141f3558482"
integrity sha512-+w7BZCvkewSmaRM6H4L2QM3RL90teqEIHDIFXAmrW33+0jhlymnDAEdqVeCZATvxhQuio1ifoGVlJJbIiH9Ffg==
dependencies:
commander "^4.0.1"
convert-source-map "^1.1.0"
Expand Down Expand Up @@ -20277,15 +20277,10 @@ moment-timezone@^0.5.27:
dependencies:
moment ">= 2.9.0"

"moment@>= 2.9.0", moment@>=1.6.0, moment@>=2.14.0, moment@^2.10.6, moment@^2.24.0:
version "2.24.0"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.24.0.tgz#0d055d53f5052aa653c9f6eb68bb5d12bf5c2b5b"
integrity sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==

moment@^2.19.3, moment@^2.27.0:
version "2.27.0"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.27.0.tgz#8bff4e3e26a236220dfe3e36de756b6ebaa0105d"
integrity sha512-al0MUK7cpIcglMv3YF13qSgdAIqxHTO7brRtaz3DlSULbqfazqkc5kEjNrLDOM7fsjshoFIihnU8snrP7zUvhQ==
"moment@>= 2.9.0", moment@>=1.6.0, moment@>=2.14.0, moment@^2.10.6, moment@^2.19.3, moment@^2.24.0, moment@^2.27.0:
version "2.28.0"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.28.0.tgz#cdfe73ce01327cee6537b0fafac2e0f21a237d75"
integrity sha512-Z5KOjYmnHyd/ukynmFd/WwyXHd7L4J9vTI/nn5Ap9AVUgaAE15VvQ9MOGmJJygEUklupqIrFnor/tjTwRU+tQw==

monaco-editor@~0.17.0:
version "0.17.1"
Expand Down

0 comments on commit f79b2e7

Please sign in to comment.