Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Closure Support #483

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ try-import %workspace%/.bazelrc.user
# It would find the "test/*.ts" reference when compiling //src:src, and the FileCache will then error
# when TS attempts to read one of these files that doesn't belong in the compilation.
build --worker_sandboxing

# Don't allow workers for TypeScript compiler
build --strategy=TypeScriptCompile=sandboxed
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.0.0
15 changes: 11 additions & 4 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package(default_visibility = ["//:__subpackages__"])

load("@npm//@bazel/typescript:index.bzl", "ts_library")
load("//tools:ts.bzl", "ts_library")
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_binary")
load("@npm//@bazel/rollup:index.bzl", "rollup_bundle")

### Produce umd and cjs bundles

ts_library(
name = "dev",
name = "index",
srcs = ["index.ts"],
tsickle_typed = True,
deps = ["//src"],
package_name = "incrementaldom",
module_name = "incrementaldom",
visibility = ["//visibility:public"],
)

alias(
name = "dev",
actual = "index",
)

[
Expand Down Expand Up @@ -81,7 +89,6 @@ genrule(
ts_library(
name = "release",
srcs = [":release_index"],
tsickle_typed = True,
deps = ["//release"],
)

Expand Down
32 changes: 32 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ http_archive(
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/4.6.0/rules_nodejs-4.6.0.tar.gz"],
)

http_archive(
name = "rules_nodejs",
sha256 = "ddb78717b802f8dd5d4c01c340ecdc007c8ced5c1df7db421d0df3d642ea0580",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/4.6.0/rules_nodejs-4.6.0.tar.gz"],
)

load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories")

node_repositories(package_json = ["//:package.json"])
Expand All @@ -32,6 +38,21 @@ Try running `npm run bazel` instead.
minimum_bazel_version = "0.21.0",
)

# Setup Closure tools
http_archive(
name = "io_bazel_rules_closure",
sha256 = "7d206c2383811f378a5ef03f4aacbcf5f47fd8650f6abbc3fa89f3a27dd8b176",
strip_prefix = "rules_closure-0.10.0",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_closure/archive/0.10.0.tar.gz",
"https://github.com/bazelbuild/rules_closure/archive/0.10.0.tar.gz",
],
)

load("@io_bazel_rules_closure//closure:repositories.bzl", "rules_closure_dependencies", "rules_closure_toolchains")
rules_closure_dependencies()
rules_closure_toolchains()

# Setup the Node.js toolchain & install our npm dependencies into @npm
npm_install(
name = "npm",
Expand All @@ -56,3 +77,14 @@ browser_repositories(
chromium = True,
firefox = True,
)

# Grab `tsickle` for `tslib` sources
http_archive(
name = "com_google_angular_tsickle_tslib",
sha256 = "1cc046dd9f56041c03ca55f81e580aa1b1a6385fa95ed65abc0d70992231dd5a",
strip_prefix = "tsickle-888aba275b9d7070880b64afbf3534dd55f0f72c/third_party/tslib",
build_file = "tsickle.bzl",
urls = [
"https://github.com/angular/tsickle/archive/888aba275b9d7070880b64afbf3534dd55f0f72c.tar.gz",
],
)
43 changes: 43 additions & 0 deletions closure/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package(
default_visibility = ["//visibility:public"],
)

load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library", "closure_js_binary")

IDOM_SUPPRESSIONS = [
"JSC_REQUIRES_NOT_SORTED",
]

IDOM_DEPS = [
"@io_bazel_rules_closure//closure/templates:soy_tslib",
]


closure_js_library(
name = "src",
srcs = glob(["src/**/*.js"]),
lenient = True,
deps = IDOM_DEPS,
suppress = IDOM_SUPPRESSIONS,
)

closure_js_library(
name = "index",
srcs = ["index.js"],
exports = [":src"],
lenient = True,
deps = [":src"] + IDOM_DEPS,
suppress = IDOM_SUPPRESSIONS,
)

closure_js_binary(
name = "bin",
deps = [":index"] + IDOM_DEPS,
entry_points = ["goog:incrementaldom.index"],
dependency_mode = "PRUNE_LEGACY",
)

alias(
name = "closure",
actual = "index",
)
9 changes: 9 additions & 0 deletions closure/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** @license SPDX-License-Identifier: Apache-2.0 */
export { applyAttr, applyProp, attributes, createAttributeMap } from './src/attributes';
export { alignWithDOM, alwaysDiffAttributes, close, createPatchInner, createPatchOuter, currentElement, currentContext, currentPointer, open, patchInner as patch, patchInner, patchOuter, skip, skipNode, tryGetCurrentElement } from './src/core';
export { setKeyAttributeName } from './src/global';
export { clearCache, getKey, importNode, isDataInitialized } from './src/node_data';
export { notifications } from './src/notifications';
export { symbols } from './src/symbols';
export { applyAttrs, applyStatics, attr, elementClose, elementOpen, elementOpenEnd, elementOpenStart, elementVoid, key, text } from './src/virtual_elements';
export * from './src/types';
81 changes: 81 additions & 0 deletions closure/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions closure/index_es5_tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"compilerOptions": {"target": "es2015", "module": "umd", "downlevelIteration": true, "skipDefaultLibCheck": true, "moduleResolution": "node", "outDir": "../../../bazel-out/darwin-fastbuild/bin", "rootDir": "../../..", "rootDirs": ["../../..", "../../../bazel-out/darwin-fastbuild/bin", "../../../bazel-out/darwin-fastbuild/bin"], "baseUrl": "../../..", "paths": {"@incremental_dom/src": ["src", "bazel-out/darwin-fastbuild/bin/src", "bazel-out/darwin-fastbuild/bin/src"], "@incremental_dom/src/*": ["src/*", "bazel-out/darwin-fastbuild/bin/src/*", "bazel-out/darwin-fastbuild/bin/src/*"], "incremental_dom": ["", "bazel-out/darwin-fastbuild/bin/", "bazel-out/darwin-fastbuild/bin/"], "incremental_dom/*": ["./*", "bazel-out/darwin-fastbuild/bin/*", "bazel-out/darwin-fastbuild/bin/*"], "*": ["external/npm/node_modules/*", "external/npm/node_modules/@types/*"]}, "preserveConstEnums": false, "experimentalDecorators": true, "emitDecoratorMetadata": true, "jsx": "react", "noErrorTruncation": false, "noEmitOnError": false, "declaration": true, "declarationDir": "../../../bazel-out/darwin-fastbuild/bin", "stripInternal": true, "inlineSourceMap": true, "inlineSources": true, "sourceMap": false, "typeRoots": ["../../../external/npm/node_modules/@types"], "types": []}, "bazelOptions": {"workspaceName": "incremental_dom", "target": "//:index", "package": "", "tsickleGenerateExterns": true, "tsickleExternsPath": "", "untyped": false, "typeBlackListPaths": [], "ignoreWarningPaths": [], "es5Mode": true, "manifest": "bazel-out/darwin-fastbuild/bin/index.es5.MF", "compilationTargetSrc": ["index.ts"], "addDtsClutzAliases": false, "typeCheckDependencies": false, "expectedDiagnostics": [], "typeCheck": true, "allowedStrictDeps": ["bazel-out/darwin-fastbuild/bin/src/debug.d.ts", "bazel-out/darwin-fastbuild/bin/src/assertions.d.ts", "bazel-out/darwin-fastbuild/bin/src/attributes.d.ts", "bazel-out/darwin-fastbuild/bin/src/changes.d.ts", "bazel-out/darwin-fastbuild/bin/src/context.d.ts", "bazel-out/darwin-fastbuild/bin/src/core.d.ts", "bazel-out/darwin-fastbuild/bin/src/diff.d.ts", "bazel-out/darwin-fastbuild/bin/src/dom_util.d.ts", "bazel-out/darwin-fastbuild/bin/src/global.d.ts", "bazel-out/darwin-fastbuild/bin/src/node_data.d.ts", "bazel-out/darwin-fastbuild/bin/src/nodes.d.ts", "bazel-out/darwin-fastbuild/bin/src/notifications.d.ts", "bazel-out/darwin-fastbuild/bin/src/symbols.d.ts", "bazel-out/darwin-fastbuild/bin/src/types.d.ts", "bazel-out/darwin-fastbuild/bin/src/util.d.ts", "bazel-out/darwin-fastbuild/bin/src/virtual_elements.d.ts", "index.ts"], "moduleName": "incremental_dom", "nodeModulesPrefix": "external/npm/node_modules"}, "files": ["../../../external/npm/node_modules/typescript/lib/protocol.d.ts", "../../../external/npm/node_modules/typescript/lib/tsserverlibrary.d.ts", "../../../external/npm/node_modules/typescript/lib/typescript.d.ts", "../../../external/npm/node_modules/typescript/lib/typescriptServices.d.ts", "../../../bazel-out/darwin-fastbuild/bin/src/debug.d.ts", "../../../bazel-out/darwin-fastbuild/bin/src/assertions.d.ts", "../../../bazel-out/darwin-fastbuild/bin/src/attributes.d.ts", "../../../bazel-out/darwin-fastbuild/bin/src/changes.d.ts", "../../../bazel-out/darwin-fastbuild/bin/src/context.d.ts", "../../../bazel-out/darwin-fastbuild/bin/src/core.d.ts", "../../../bazel-out/darwin-fastbuild/bin/src/diff.d.ts", "../../../bazel-out/darwin-fastbuild/bin/src/dom_util.d.ts", "../../../bazel-out/darwin-fastbuild/bin/src/global.d.ts", "../../../bazel-out/darwin-fastbuild/bin/src/node_data.d.ts", "../../../bazel-out/darwin-fastbuild/bin/src/nodes.d.ts", "../../../bazel-out/darwin-fastbuild/bin/src/notifications.d.ts", "../../../bazel-out/darwin-fastbuild/bin/src/symbols.d.ts", "../../../bazel-out/darwin-fastbuild/bin/src/types.d.ts", "../../../bazel-out/darwin-fastbuild/bin/src/util.d.ts", "../../../bazel-out/darwin-fastbuild/bin/src/virtual_elements.d.ts", "../../../index.ts"], "compileOnSave": false, "extends": "../../../tsconfig"}
86 changes: 86 additions & 0 deletions closure/src/assertions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/** @license SPDX-License-Identifier: Apache-2.0 */
import { NameOrCtorDef } from "./types";
/**
* Asserts that a value exists and is not null or undefined. goog.asserts
* is not used in order to avoid dependencies on external code.
* @param val The value to assert is truthy.
* @returns The value.
*/
declare function assert<T extends {}>(val: T | null | undefined): T;
/**
* Makes sure that there is a current patch context.
* @param functionName The name of the caller, for the error message.
*/
declare function assertInPatch(functionName: string): void;
/**
* Makes sure that a patch closes every node that it opened.
* @param openElement
* @param root
*/
declare function assertNoUnclosedTags(openElement: Node | null, root: Node | DocumentFragment): void;
/**
* Makes sure that node being outer patched has a parent node.
* @param parent
*/
declare function assertPatchOuterHasParentNode(parent: Node | null): void;
/**
* Makes sure that the caller is not where attributes are expected.
* @param functionName The name of the caller, for the error message.
*/
declare function assertNotInAttributes(functionName: string): void;
/**
* Makes sure that the caller is not inside an element that has declared skip.
* @param functionName The name of the caller, for the error message.
*/
declare function assertNotInSkip(functionName: string): void;
/**
* Makes sure that the caller is where attributes are expected.
* @param functionName The name of the caller, for the error message.
*/
declare function assertInAttributes(functionName: string): void;
/**
* Makes sure the patch closes virtual attributes call
*/
declare function assertVirtualAttributesClosed(): void;
/**
* Makes sure that tags are correctly nested.
* @param currentNameOrCtor
* @param nameOrCtor
*/
declare function assertCloseMatchesOpenTag(currentNameOrCtor: NameOrCtorDef, nameOrCtor: NameOrCtorDef): void;
/**
* Makes sure that no children elements have been declared yet in the current
* element.
* @param functionName The name of the caller, for the error message.
* @param previousNode
*/
declare function assertNoChildrenDeclaredYet(functionName: string, previousNode: Node | null): void;
/**
* Checks that a call to patchOuter actually patched the element.
* @param maybeStartNode The value for the currentNode when the patch
* started.
* @param maybeCurrentNode The currentNode when the patch finished.
* @param expectedNextNode The Node that is expected to follow the
* currentNode after the patch;
* @param expectedPrevNode The Node that is expected to preceed the
* currentNode after the patch.
*/
declare function assertPatchElementNoExtras(maybeStartNode: Node | null, maybeCurrentNode: Node | null, expectedNextNode: Node | null, expectedPrevNode: Node | null): void;
/**
* @param newContext The current patch context.
*/
declare function updatePatchContext(newContext: {} | null): void;
/**
* Updates the state of being in an attribute declaration.
* @param value Whether or not the patch is in an attribute declaration.
* @return the previous value.
*/
declare function setInAttributes(value: boolean): boolean;
/**
* Updates the state of being in a skip element.
* @param value Whether or not the patch is skipping the children of a
* parent node.
* @return the previous value.
*/
declare function setInSkip(value: boolean): boolean;
export { assert, assertInPatch, assertNoUnclosedTags, assertNotInAttributes, assertInAttributes, assertCloseMatchesOpenTag, assertVirtualAttributesClosed, assertNoChildrenDeclaredYet, assertNotInSkip, assertPatchElementNoExtras, assertPatchOuterHasParentNode, setInAttributes, setInSkip, updatePatchContext };
Loading