Skip to content

Commit 90effb1

Browse files
committed
Make TensorBoard work in raw sources mode
With this change we withdraw our support for the ECMA `import` keyword hitherto mandated by certain tools. In doing so, TensorBoard compiles in seconds, rather than taking a minute. The ES6 `import` standard only defines / and ./ prefixed paths. All other paths that exist are undefined. Since most tooling and early-adopter codebases rely on the undefined behavior, the standard itself is mostly syntactic sugar (that isn't even sweet.) The true problem is having a world where Closure, Node, and web server namespaces coexist. The ES6 `import` keyword makes JavaScript incompatible with web browsers. The support added in Chrome 61 is not sufficient, as it only allows the `export` keyword on functions and not variables. This is a point of view much different from early-adopters, which raises concerns that the standard is unlikely to gain a meaningful consensus. The ES6 `import` keyword makes TypeScript incompatible with web browsers. This keyword is not supported by the TypeScript compiler. All it can do is punt the problem to rollup. However we can't use rollup since it doesn't support Closure namespaces. The only tool that supports all three of Web, Node, and Closure namespaces is the Closure Compiler. Without it, ES6 TypeScript or JavaScript can't run in any web browser. But since the Closure Compiler was designed to create production builds for google.com, it isn't very fast. Therefore it's unreasonable that developers on a small project like TensorBoard should be expected to wait on this tool whenever making one line changes in a development iteration cycle. Since the Closure Tools were originally designed to be compatible with web browsers in the absense of tooling, this change seeks to bring TensorBoard back into accordance with those principles.
1 parent bfcdfa9 commit 90effb1

File tree

129 files changed

+720
-820
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+720
-820
lines changed

tensorboard/components/tf_backend/backend.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
15-
16-
import {compareTagNames} from '../vz-sorting/sorting.js';
17-
import {RequestManager} from './requestManager.js';
18-
import {getRouter} from './router.js';
15+
namespace tf_backend {
1916

2017
export type RunToTag = {
2118
[run: string]: string[];
@@ -44,13 +41,13 @@ export type DebuggerNumericsAlertReportResponse = DebuggerNumericsAlertReport[];
4441
export const TYPES = [];
4542

4643
/** Given a RunToTag, return sorted array of all runs */
47-
export function getRuns(r: RunToTag): string[] {
48-
return _.keys(r).sort(compareTagNames);
44+
export function getRunsNamed(r: RunToTag): string[] {
45+
return _.keys(r).sort(vz_sorting.compareTagNames);
4946
}
5047

5148
/** Given a RunToTag, return array of all tags (sorted + dedup'd) */
5249
export function getTags(r: RunToTag): string[] {
53-
return _.union.apply(null, _.values(r)).sort(compareTagNames);
50+
return _.union.apply(null, _.values(r)).sort(vz_sorting.compareTagNames);
5451
}
5552

5653
/**
@@ -61,7 +58,7 @@ export function getTags(r: RunToTag): string[] {
6158
export function filterTags(r: RunToTag, runs: string[]): string[] {
6259
let result = [];
6360
runs.forEach((x) => result = result.concat(r[x]));
64-
return _.uniq(result).sort(compareTagNames);
61+
return _.uniq(result).sort(vz_sorting.compareTagNames);
6562
}
6663

6764
function timeToDate(x: number): Date {
@@ -91,9 +88,10 @@ function detupler<T, G>(xform: (x: T) => G): (t: TupleData<T>) => Datum & G {
9188
};
9289
};
9390

94-
9591
/**
9692
* The following interface (TupleData) describes how the data is sent
9793
* over from the backend.
9894
*/
9995
type TupleData<T> = [number, number, T]; // wall_time, step
96+
97+
} // namespace tf_backend

tensorboard/components/tf_backend/canceller.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
15+
namespace tf_backend {
1516

1617
/**
1718
* A class that allows marking promises as cancelled.
@@ -63,3 +64,5 @@ export class Canceller {
6364
this.cancellationCount++;
6465
}
6566
}
67+
68+
} // namespace tf_backend

tensorboard/components/tf_backend/requestManager.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
15+
namespace tf_backend {
1516

1617
interface ResolveReject {
1718
resolve: Function;
1819
reject: Function;
1920
}
21+
2022
/**
2123
* Manages many fetch requests. Launches up to nSimultaneousRequests
2224
* simultaneously, and maintains a LIFO queue of requests to process when
@@ -175,3 +177,5 @@ export class RequestManager {
175177
});
176178
}
177179
}
180+
181+
} // namespace tf_backend

tensorboard/components/tf_backend/router.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
15-
16-
import {addParams} from './urlPathHelpers.js';
15+
namespace tf_backend {
1716

1817
export interface Router {
1918
logdir: () => string;
@@ -76,3 +75,5 @@ export function setRouter(router: Router): void {
7675
}
7776
_router = router;
7877
}
78+
79+
} // namespace tf_backend

tensorboard/components/tf_backend/runsStore.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
15-
16-
import {RequestManager} from './requestManager.js';
17-
import {getRouter} from './router.js';
15+
namespace tf_backend {
1816

1917
let runs: string[] = [];
2018

@@ -66,3 +64,5 @@ export function fetchRuns(): Promise<void> {
6664
export function getRuns(): string[] {
6765
return runs.slice();
6866
}
67+
68+
} // namespace tf_backend

tensorboard/components/tf_backend/test/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@ ts_web_library(
2222
"//tensorboard/components/tf_imports:webcomponentsjs",
2323
],
2424
)
25-

tensorboard/components/tf_backend/test/backendTests.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
15-
16-
import {filterTags, getRuns, getTags, RunToTag, TYPES} from '../backend.js';
17-
import {RequestManager} from '../requestManager.js';
18-
import {createRouter, setRouter} from '../router.js';
19-
import {addParams} from '../urlPathHelpers.js';
15+
namespace tf_backend {
2016

2117
describe('urlPathHelpers', () => {
2218
it('addParams leaves input untouched when there are no parameters', () => {
@@ -67,17 +63,19 @@ describe('backend tests', () => {
6763
};
6864
const empty1: RunToTag = {};
6965
const empty2: RunToTag = {run1: [], run2: []};
70-
chai.assert.deepEqual(getRuns(r2t), ['a', 'run1', 'run2']);
66+
chai.assert.deepEqual(getRunsNamed(r2t), ['a', 'run1', 'run2']);
7167
chai.assert.deepEqual(getTags(r2t), ['bar', 'foo', 'zod', 'zoink']);
7268
chai.assert.deepEqual(filterTags(r2t, ['run1', 'run2']), getTags(r2t));
7369
chai.assert.deepEqual(filterTags(r2t, ['run1']), ['bar', 'foo', 'zod']);
7470
chai.assert.deepEqual(
7571
filterTags(r2t, ['run2', 'a']), ['foo', 'zod', 'zoink']);
7672

77-
chai.assert.deepEqual(getRuns(empty1), []);
73+
chai.assert.deepEqual(getRunsNamed(empty1), []);
7874
chai.assert.deepEqual(getTags(empty1), []);
7975

80-
chai.assert.deepEqual(getRuns(empty2), ['run1', 'run2']);
76+
chai.assert.deepEqual(getRunsNamed(empty2), ['run1', 'run2']);
8177
chai.assert.deepEqual(getTags(empty2), []);
8278
});
8379
});
80+
81+
} // namespace tf_backend

tensorboard/components/tf_backend/test/requestManagerTests.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
15-
16-
import {RequestManager, RequestNetworkError} from '../requestManager.js';
15+
namespace tf_backend {
1716

1817
interface MockRequest {
1918
resolve: Function;
@@ -292,3 +291,5 @@ describe('backend', () => {
292291
});
293292
});
294293
});
294+
295+
} // namespace tf_backend

tensorboard/components/tf_backend/urlPathHelpers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
15+
namespace tf_backend {
16+
1517
/**
1618
* A query parameter value can either be a string or a list of strings.
1719
* A string `"foo"` is encoded as `key=foo`; a list `["foo", "bar"]` is
@@ -51,3 +53,5 @@ function _encodeURIComponent(x: string): string {
5153
// Replace parentheses for consistency with Python's urllib.urlencode.
5254
return encodeURIComponent(x).replace(/\(/g, '%28').replace(/\)/g, '%29');
5355
}
56+
57+
} // namespace tf_backend

tensorboard/components/tf_card_heading/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ts_web_library(
1010
"tf-card-heading.html",
1111
"tf-card-heading-style.html",
1212
"util.html",
13-
"util.js",
13+
"util.ts",
1414
],
1515
path = "/tf-card-heading",
1616
visibility = ["//visibility:public"],

0 commit comments

Comments
 (0)