Skip to content

Commit

Permalink
Merge pull request #63 from player-ui/xlr-entries
Browse files Browse the repository at this point in the history
Add XLR entries to generated package.json
  • Loading branch information
adierkens authored Aug 5, 2024
2 parents affc386 + 6793960 commit 28875b8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
11 changes: 7 additions & 4 deletions docs/javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ Public API for JavaScript based project rules
## create_package_json

<pre>
create_package_json(<a href="#create_package_json-name">name</a>, <a href="#create_package_json-base_package_json">base_package_json</a>, <a href="#create_package_json-custom_entrypoints">custom_entrypoints</a>, <a href="#create_package_json-dependencies">dependencies</a>, <a href="#create_package_json-native_bundle">native_bundle</a>,
<a href="#create_package_json-peer_dependencies">peer_dependencies</a>, <a href="#create_package_json-placeholder_version">placeholder_version</a>, <a href="#create_package_json-root_package_json">root_package_json</a>, <a href="#create_package_json-stamp">stamp</a>, <a href="#create_package_json-substitutions">substitutions</a>)
create_package_json(<a href="#create_package_json-name">name</a>, <a href="#create_package_json-additional_exports">additional_exports</a>, <a href="#create_package_json-base_package_json">base_package_json</a>, <a href="#create_package_json-custom_entrypoints">custom_entrypoints</a>, <a href="#create_package_json-dependencies">dependencies</a>,
<a href="#create_package_json-native_bundle">native_bundle</a>, <a href="#create_package_json-peer_dependencies">peer_dependencies</a>, <a href="#create_package_json-placeholder_version">placeholder_version</a>, <a href="#create_package_json-root_package_json">root_package_json</a>, <a href="#create_package_json-stamp">stamp</a>,
<a href="#create_package_json-substitutions">substitutions</a>)
</pre>


Expand All @@ -19,6 +20,7 @@ create_package_json(<a href="#create_package_json-name">name</a>, <a href="#crea
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="create_package_json-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="create_package_json-additional_exports"></a>additional_exports | Additional entrypoints to add to the generated package.json | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
| <a id="create_package_json-base_package_json"></a>base_package_json | A .json file to use to add additional properties to the generated package. This can often be a 'package.json' and the entries/outputs/dependencies will be filled in later on. | <a href="https://bazel.build/concepts/labels">Label</a> | required | |
| <a id="create_package_json-custom_entrypoints"></a>custom_entrypoints | If custom main/module/types entrypoints are specified and shouldn't be overwritten | Boolean | optional | `False` |
| <a id="create_package_json-dependencies"></a>dependencies | The dependencies of the package. These will be added to the base package.json | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
Expand Down Expand Up @@ -59,8 +61,8 @@ A test target that runs eslint on the given sources.

<pre>
js_pipeline(<a href="#js_pipeline-package_name">package_name</a>, <a href="#js_pipeline-name">name</a>, <a href="#js_pipeline-srcs">srcs</a>, <a href="#js_pipeline-package_json">package_json</a>, <a href="#js_pipeline-root_package_json">root_package_json</a>, <a href="#js_pipeline-vitest_config">vitest_config</a>, <a href="#js_pipeline-tsup_config">tsup_config</a>,
<a href="#js_pipeline-node_modules">node_modules</a>, <a href="#js_pipeline-deps">deps</a>, <a href="#js_pipeline-native_bundle">native_bundle</a>, <a href="#js_pipeline-private">private</a>, <a href="#js_pipeline-peer_deps">peer_deps</a>, <a href="#js_pipeline-include_packaging_targets">include_packaging_targets</a>,
<a href="#js_pipeline-test_deps">test_deps</a>, <a href="#js_pipeline-lint_deps">lint_deps</a>, <a href="#js_pipeline-build_deps">build_deps</a>)
<a href="#js_pipeline-node_modules">node_modules</a>, <a href="#js_pipeline-deps">deps</a>, <a href="#js_pipeline-native_bundle">native_bundle</a>, <a href="#js_pipeline-private">private</a>, <a href="#js_pipeline-peer_deps">peer_deps</a>, <a href="#js_pipeline-create_package_json_args">create_package_json_args</a>,
<a href="#js_pipeline-include_packaging_targets">include_packaging_targets</a>, <a href="#js_pipeline-test_deps">test_deps</a>, <a href="#js_pipeline-lint_deps">lint_deps</a>, <a href="#js_pipeline-build_deps">build_deps</a>)
</pre>

The main entry point for any JS/TS project. `js_pipeline` should be the only thing you need in your BUILD file.
Expand All @@ -85,6 +87,7 @@ Creates a js_library, npm_package, and test targets for a given package.
| <a id="js_pipeline-native_bundle"></a>native_bundle | The name for the native bundle global if defined. | `None` |
| <a id="js_pipeline-private"></a>private | Whether or not the package should be private (skipping an npm release). | `False` |
| <a id="js_pipeline-peer_deps"></a>peer_deps | The peer dependencies for the package. | `[]` |
| <a id="js_pipeline-create_package_json_args"></a>create_package_json_args | Additional arguments to pass to the package_json creation | `{}` |
| <a id="js_pipeline-include_packaging_targets"></a>include_packaging_targets | Additional dependencies to add to the package target | `[]` |
| <a id="js_pipeline-test_deps"></a>test_deps | The test dependencies for the package. | `["//:vitest_config"]` |
| <a id="js_pipeline-lint_deps"></a>lint_deps | The lint dependencies for the package. | `["//:eslint_config"]` |
Expand Down
7 changes: 5 additions & 2 deletions javascript/private/create_package_json.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ async function main(args) {
native_bundle,
substitutions,
custom_entrypoints,
additional_exports,
BAZEL_STABLE_STATUS_FILE,
BAZEL_VOLATILE_STATUS_FILE,
} = args;
Expand Down Expand Up @@ -171,6 +172,9 @@ async function main(args) {
}, parsedBasePackageJson.peerDependencies ?? {});

const packageJson = {
sideEffects: false,
files: ["dist", "src", "types"],

...parsedBasePackageJson,
...(!custom_entrypoints
? {
Expand All @@ -184,7 +188,6 @@ async function main(args) {
bundle: `dist/${native_bundle}.native.js`,
}
: {}),
sideEffects: false,
...(!custom_entrypoints
? {
exports: {
Expand All @@ -195,10 +198,10 @@ async function main(args) {
import: "./dist/index.mjs",
default: "./dist/cjs/index.cjs",
},
...(additional_exports ?? {}),
},
}
: {}),
files: ["dist", "src", "types"],
dependencies: replaceWorkspaceReferenceWithVersion(
versionedDependencies,
"0.0.0-PLACEHOLDER"
Expand Down
3 changes: 3 additions & 0 deletions javascript/private/js_pipeline.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def js_pipeline(
native_bundle = None,
private = False,
peer_deps = [],
create_package_json_args = {},
include_packaging_targets = [],
test_deps = ["//:vitest_config"],
lint_deps = ["//:eslint_config"],
Expand All @@ -51,6 +52,7 @@ def js_pipeline(
deps: The dependencies for the package.
native_bundle: The name for the native bundle global if defined.
private: Whether or not the package should be private (skipping an npm release).
create_package_json_args: Additional arguments to pass to the package_json creation
include_packaging_targets: Additional dependencies to add to the package target
peer_deps: The peer dependencies for the package.
test_deps: The test dependencies for the package.
Expand Down Expand Up @@ -150,6 +152,7 @@ def js_pipeline(
substitutions = {
"0.0.0-PLACEHOLDER": "{STABLE_VERSION}",
},
**create_package_json_args
)

js_library_name = name + "_js_library"
Expand Down
2 changes: 2 additions & 0 deletions javascript/private/package_json.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def _package_json_impl(ctx):
stamp_inputs = []

args = {
"additional_exports": ctx.attr.additional_exports,
"base_package_json": ctx.file.base_package_json.short_path,
"custom_entrypoints": ctx.attr.custom_entrypoints,
"dependencies": [get_js_npm_name(dep) for dep in ctx.attr.dependencies],
Expand Down Expand Up @@ -48,6 +49,7 @@ def _package_json_impl(ctx):
create_package_json = rule(
implementation = _package_json_impl,
attrs = dict({
"additional_exports": attr.string_dict(default = {}, doc = "Additional entrypoints to add to the generated package.json"),
"base_package_json": attr.label(
mandatory = True,
doc = """A .json file to use to add additional properties to the generated package.
Expand Down
5 changes: 5 additions & 0 deletions player/private/js_xlr_pipeline.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,10 @@ def js_xlr_pipeline(name = None, xlr_mode = "plugin", xlr_input_dir = "src", src
include_packaging_targets = [
":" + name + "_xlr",
],
create_package_json_args = {
"additional_exports": {
"./dist/xlr/*": "./dist/xlr/*",
},
},
**kwargs
)

0 comments on commit 28875b8

Please sign in to comment.