Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/kbn-plugin-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
"author": "Spencer Alger <email@spalger.com>",
"license": "Apache-2.0",
"dependencies": {
"@babel/core": "^7.4.4",
"@kbn/babel-preset": "1.0.0",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: with this change on the latest master I'm getting error Couldn't find package "@kbn/babel-preset@1.0.0" required by "@kbn/plugin-helpers@link:../../kibana/packages/kbn-plugin-helpers" on the "npm" registry. on yarn kbn bootstrap (right after yarn kbn clean). Am I doing something wrong? :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That package is still at 1.0.0 locally, and it works for me, but we've been doing a fair amount of upgrades lately and I've had to wipe out my node_modules directory more frequently than desired because yarn isn't able to properly patch the directory correctly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's weird, yarn kbn clean should remove node_modules, but that still doesn't help. Anyway, if it becomes annoying, I'll try to investigate and give you folks more details :)

"argv-split": "^2.0.1",
"commander": "^2.9.0",
"del": "^4.0.0",
"execa": "^1.0.0",
"gulp-rename": "1.4.0",
"globby": "^8.0.1",
"gulp-babel": "^8.0.0",
"gulp-rename": "1.4.0",
"gulp-zip": "4.1.0",
"inquirer": "^1.2.2",
"minimatch": "^3.0.4",
Expand Down
56 changes: 44 additions & 12 deletions packages/kbn-plugin-helpers/tasks/build/create_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ const vfs = require('vinyl-fs');
const rename = require('gulp-rename');
const through = require('through2');
const minimatch = require('minimatch');
const gulpBabel = require('gulp-babel');
const { promisify } = require('util');
const { pipeline } = require('stream');

const rewritePackageJson = require('./rewrite_package_json');
const winCmd = require('../../lib/win_cmd');

const asyncPipeline = promisify(pipeline);

// `link:` dependencies create symlinks, but we don't want to include symlinks
// in the built zip file. Therefore we remove all symlinked dependencies, so we
// can re-create them when installing the plugin.
Expand Down Expand Up @@ -65,6 +70,31 @@ function parseTsconfig(pluginSourcePath, configPath) {
return config;
}

// transpile with babel
async function transpileWithBabel(srcGlobs, buildRoot, presets) {
await asyncPipeline(
vfs.src(
srcGlobs.concat([
'!**/*.d.ts',
'!**/*.{test,test.mocks,mock,mocks}.{ts,tsx}',
'!**/node_modules/**',
'!**/bower_components/**',
'!**/__tests__/**',
]),
{
cwd: buildRoot,
}
),

gulpBabel({
babelrc: false,
presets,
}),

vfs.dest(buildRoot)
);
}

module.exports = function createBuild(plugin, buildTarget, buildVersion, kibanaVersion, files) {
const buildSource = plugin.root;
const buildRoot = path.join(buildTarget, 'kibana', plugin.id);
Expand Down Expand Up @@ -122,19 +152,13 @@ module.exports = function createBuild(plugin, buildTarget, buildVersion, kibanaV

del.sync([path.join(buildRoot, '**', '*.s{a,c}ss')]);
})
.then(function() {
.then(async function() {
const buildConfigPath = path.join(buildRoot, 'tsconfig.json');

if (!existsSync(buildConfigPath)) {
return;
}

if (!plugin.pkg.devDependencies.typescript) {
throw new Error(
'Found tsconfig.json file in plugin but typescript is not a devDependency.'
);
}

// attempt to patch the extends path in the tsconfig file
const buildConfig = parseTsconfig(buildSource, buildConfigPath);

Expand All @@ -144,11 +168,19 @@ module.exports = function createBuild(plugin, buildTarget, buildVersion, kibanaV
writeFileSync(buildConfigPath, JSON.stringify(buildConfig));
}

execa.sync(
path.join(buildSource, 'node_modules', '.bin', winCmd('tsc')),
['--pretty', 'true'],
{ cwd: buildRoot }
);
// Transpile ts server code
//
// Include everything except content from public folders
await transpileWithBabel(['**/*.{ts,tsx}', '!**/public/**'], buildRoot, [
require.resolve('@kbn/babel-preset/node_preset'),
]);

// Transpile ts client code
//
// Include everything inside a public directory
await transpileWithBabel(['**/public/**/*.{ts,tsx}'], buildRoot, [
require.resolve('@kbn/babel-preset/webpack_preset'),
]);

del.sync([
path.join(buildRoot, '**', '*.{ts,tsx,d.ts}'),
Expand Down
Loading