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
9 changes: 8 additions & 1 deletion packages/analytics/client/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ jsts_transpiler(
build_pkg_name = package_name(),
)

jsts_transpiler(
name = "target_web",
srcs = SRCS,
build_pkg_name = package_name(),
web = True,
)

ts_config(
name = "tsconfig",
src = "tsconfig.json",
Expand All @@ -86,7 +93,7 @@ ts_project(
js_library(
name = PKG_DIRNAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node"],
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)
Expand Down
1 change: 1 addition & 0 deletions packages/analytics/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@kbn/analytics-client",
"private": true,
"version": "1.0.0",
"browser": "./target_web/index.js",
"main": "./target_node/index.js",
"license": "SSPL-1.0 OR Elastic License 2.0"
}
9 changes: 8 additions & 1 deletion packages/analytics/shippers/fullstory/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ jsts_transpiler(
build_pkg_name = package_name(),
)

jsts_transpiler(
name = "target_web",
srcs = SRCS,
build_pkg_name = package_name(),
web = True,
)

ts_config(
name = "tsconfig",
src = "tsconfig.json",
Expand All @@ -86,7 +93,7 @@ ts_project(
js_library(
name = PKG_DIRNAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node"],
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)
Expand Down
1 change: 1 addition & 0 deletions packages/analytics/shippers/fullstory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@kbn/analytics-shippers-fullstory",
"private": true,
"version": "1.0.0",
"browser": "./target_web/index.js",
"main": "./target_node/index.js",
"license": "SSPL-1.0 OR Elastic License 2.0"
}
15 changes: 14 additions & 1 deletion packages/kbn-ace/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ jsts_transpiler(
build_pkg_name = package_name(),
)

jsts_transpiler(
name = "target_web",
srcs = SRCS,
additional_args = [
"--copy-files",
"--ignore",
"**/*/src/ace/modes/x_json/worker/x_json.ace.worker.js",
"--quiet"
],
build_pkg_name = package_name(),
web = True,
)

ts_config(
name = "tsconfig",
src = "tsconfig.json",
Expand All @@ -77,7 +90,7 @@ ts_project(
js_library(
name = PKG_BASE_NAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node"],
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-ace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@kbn/ace",
"version": "1.0.0",
"private": true,
"browser": "./target_web/index.js",
"main": "./target_node/index.js",
"license": "SSPL-1.0 OR Elastic License 2.0"
}
9 changes: 8 additions & 1 deletion packages/kbn-doc-links/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ jsts_transpiler(
build_pkg_name = package_name(),
)

jsts_transpiler(
name = "target_web",
srcs = SRCS,
build_pkg_name = package_name(),
web = True,
)

ts_config(
name = "tsconfig",
src = "tsconfig.json",
Expand All @@ -69,7 +76,7 @@ ts_project(
js_library(
name = PKG_BASE_NAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node"],
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-doc-links/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@kbn/doc-links",
"browser": "./target_web/index.js",
"main": "./target_node/index.js",
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0",
Expand Down
17 changes: 12 additions & 5 deletions packages/kbn-field-types/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,17 @@ TYPES_DEPS = [
]

jsts_transpiler(
name = "target_node",
srcs = SRCS,
build_pkg_name = package_name(),
)
name = "target_node",
srcs = SRCS,
build_pkg_name = package_name(),
)

jsts_transpiler(
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like this was repeated.

Copy link
Member Author

Choose a reason for hiding this comment

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

@mattkime we are intentionally transpiling twice with different names and Babel presets:

  1. target_node - optimized for Node.js environment
  2. target_web - optimized for running in browsers (mind the additional parameter web = True). Among other things, it applies the necessary transpilation and polyfills to support ourbrowserlist compatibility matrix.

If your package only runs on the UI and you think target_node is not necessary, we can discuss with @elastic/kibana-operations if it's ok to remove it or if target_node must always exist.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, not duplicate!

name = "target_web",
srcs = SRCS,
build_pkg_name = package_name(),
web = True,
)

ts_config(
name = "tsconfig",
Expand All @@ -72,7 +79,7 @@ ts_project(
js_library(
name = PKG_BASE_NAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node"],
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-field-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"version": "1.0.0",
"private": true,
"license": "SSPL-1.0 OR Elastic License 2.0",
"browser": "./target_web/index.js",
"main": "./target_node/index.js"
}
9 changes: 8 additions & 1 deletion packages/kbn-interpreter/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ jsts_transpiler(
build_pkg_name = package_name(),
)

jsts_transpiler(
name = "target_web",
srcs = SRCS,
build_pkg_name = package_name(),
web = True,
)

peggy(
name = "grammar",
data = [
Expand Down Expand Up @@ -82,7 +89,7 @@ ts_project(
js_library(
name = PKG_BASE_NAME,
srcs = NPM_MODULE_EXTRA_FILES + [":grammar"],
deps = RUNTIME_DEPS + [":target_node"],
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-interpreter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@kbn/interpreter",
"author": "App Services",
"browser": "./target_web/index.js",
"main": "./target_node/index.js",
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0",
Expand Down
9 changes: 8 additions & 1 deletion packages/kbn-io-ts-utils/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ jsts_transpiler(
build_pkg_name = package_name(),
)

jsts_transpiler(
name = "target_web",
srcs = SRCS,
build_pkg_name = package_name(),
web = True,
)

ts_config(
name = "tsconfig",
src = "tsconfig.json",
Expand All @@ -73,7 +80,7 @@ ts_project(
js_library(
name = PKG_BASE_NAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node"],
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-io-ts-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@kbn/io-ts-utils",
"browser": "./target_web/index.js",
"main": "./target_node/index.js",
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0",
Expand Down
9 changes: 8 additions & 1 deletion packages/kbn-mapbox-gl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ jsts_transpiler(
build_pkg_name = package_name(),
)

jsts_transpiler(
name = "target_web",
srcs = SRCS,
build_pkg_name = package_name(),
web = True,
)

ts_config(
name = "tsconfig",
src = "tsconfig.json",
Expand All @@ -69,7 +76,7 @@ ts_project(
js_library(
name = PKG_BASE_NAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node"],
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-mapbox-gl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"version": "1.0.0",
"private": true,
"license": "SSPL-1.0 OR Elastic License 2.0",
"browser": "./target_web/index.js",
"main": "./target_node/index.js"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.
*/

import Path from 'path';

import { run } from '@kbn/dev-utils';
import { REPO_ROOT } from '@kbn/utils';

import { OptimizerConfig } from '../optimizer';
import { parseStats } from './parse_stats';

/**
* Analyzes the bundle dependencies to find any imports using the `@kbn/<package_name>/target_node` build target.
*
* We should aim for those packages to be imported using the `@kbn/<package_name>/target_web` build because it's optimized
* for browser compatibility.
*
* This utility also helps identify when code that should only run in the server is leaked into the browser.
*/
export async function runFindTargetNodeImportsCli() {
run(async ({ log }) => {
const config = OptimizerConfig.create({
includeCoreBundle: true,
repoRoot: REPO_ROOT,
});

const paths = config.bundles.map((b) => Path.resolve(b.outputDir, 'stats.json'));

log.info('analyzing', paths.length, 'stats files');
log.verbose(paths);

const imports = new Set();
for (const path of paths) {
const stats = parseStats(path);

for (const module of stats.modules) {
if (module.name.includes('/target_node/')) {
const [, cleanName] = /\/((?:kbn-|@kbn\/).+)\/target_node/.exec(module.name) ?? [];
imports.add(cleanName || module.name);
}
}
}

log.success('found', imports.size, '@kbn/*/target_node imports in entry bundles and chunks');
log.write(
Array.from(imports, (i) => `'${i}',`)
.sort()
.join('\n')
);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@

export * from './find_babel_runtime_helpers_in_entry_bundles';
export * from './find_node_libs_browser_polyfills_in_entry_bundles';
export * from './find_target_node_imports';
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export * from './node';
export * from './limits';
export * from './cli';
export * from './report_optimizer_timings';
export * from './babel_runtime_helpers';
export * from './audit_bundle_dependencies';
Copy link
Member Author

Choose a reason for hiding this comment

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

rename the dir because it no-longer contained only the logic for babel_runtime_helpers 😇

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import { ascending } from '../common';
export async function getOptimizerBuiltPaths() {
return (
await globby(
['**/*', '!**/{__fixtures__,__snapshots__,integration_tests,babel_runtime_helpers,node}/**'],
[
'**/*',
'!**/{__fixtures__,__snapshots__,integration_tests,audit_bundle_dependencies,node}/**',
],
{
cwd: Path.resolve(__dirname, '../'),
absolute: true,
Expand Down
9 changes: 8 additions & 1 deletion packages/kbn-rule-data-utils/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ jsts_transpiler(
build_pkg_name = package_name(),
)

jsts_transpiler(
name = "target_web",
srcs = SRCS,
build_pkg_name = package_name(),
web = True,
)

ts_config(
name = "tsconfig",
src = "tsconfig.json",
Expand All @@ -69,7 +76,7 @@ ts_project(
js_library(
name = PKG_BASE_NAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node"],
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-rule-data-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@kbn/rule-data-utils",
"browser": "./target_web/index.js",
"main": "./target_node/index.js",
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0",
Expand Down
9 changes: 8 additions & 1 deletion packages/kbn-securitysolution-rules/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ jsts_transpiler(
build_pkg_name = package_name(),
)

jsts_transpiler(
name = "target_web",
srcs = SRCS,
build_pkg_name = package_name(),
web = True,
)

ts_config(
name = "tsconfig",
src = "tsconfig.json",
Expand All @@ -71,7 +78,7 @@ ts_project(
js_library(
name = PKG_BASE_NAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node"],
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-securitysolution-rules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"description": "security solution rule utilities to use across plugins",
"license": "SSPL-1.0 OR Elastic License 2.0",
"browser": "./target_web/index.js",
"main": "./target_node/index.js",
"private": true
}
Loading