Skip to content

Commit 768f9c1

Browse files
committed
libdot: convert to ES6 module
Replace the generated index.js with an actual ES6 module that loads all the rest of the hterm code on the fly. This avoids the compile step when testing locally. This is structured as the minimal effort to convert libdot to an ES6 module. We still have a global "lib" object that all the imported files extend with their APIs. This avoids a lot of disruption in the tree and makes it easier to review. This also avoids confusing closure-compiler as it doesn't handle ES6 modules great where the declared types use the full `lib.xxx` namespace. Rectifying this will take some effort, and perhaps writing custom externs, neither of which is exactly great. Change-Id: Id90c8206803b52e4c301ae84e33e4fed3807a850 Reviewed-on: https://chromium-review.googlesource.com/c/apps/libapps/+/4801578 Tested-by: kokoro <[email protected]> Reviewed-by: Joel Hockey <[email protected]>
1 parent bd9b8fa commit 768f9c1

37 files changed

+114
-95
lines changed

libdot/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@ dist
55
*.min.js
66
*.js.map
77

8-
/index.js
9-
108
# npm related dirs.
119
node_modules

libdot/bin/lint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def _get_default_paths(basedir: Path) -> List[Path]:
151151
# Sort to ensure lib.js comes before lib_array.js, etc.
152152
js_files = sorted(
153153
list((libdot.DIR / "html").glob("*.html"))
154+
+ [libdot.DIR / "index.js"]
154155
+ list((libdot.DIR / "js").glob("*.js"))
155156
)
156157

libdot/bin/load_tests

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,14 @@ def test_runner_main(argv, path, serve=False, mkdeps=None):
192192
logging.info("Tests took %s", delta)
193193

194194

195+
def _mkdeps(_opts) -> None:
196+
"""Build the required deps for the test suite."""
197+
subprocess.check_call([libdot.BIN_DIR / "mkdist"])
198+
199+
195200
def main(argv):
196201
"""The main func!"""
197-
return test_runner_main(argv, TEST_PAGE, serve=True)
202+
return test_runner_main(argv, TEST_PAGE, serve=True, mkdeps=_mkdeps)
198203

199204

200205
if __name__ == "__main__":

libdot/externs/rollup-package-json.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,15 @@ default$$module$package_json.gitDate;
1919

2020
/** @type {string} */
2121
default$$module$package_json.version;
22+
23+
/** @const */
24+
const module$__$libdot$dist$js$libdot_resources = {};
25+
26+
/** @type {string} */
27+
module$__$libdot$dist$js$libdot_resources.gitCommitHash;
28+
29+
/** @type {string} */
30+
module$__$libdot$dist$js$libdot_resources.gitDate;
31+
32+
/** @type {string} */
33+
module$__$libdot$dist$js$libdot_resources.version;

libdot/html/lib_test.html

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,6 @@
1010
<!-- initialize the test framework; this must come first -->
1111
<script src='../js/lib_test.js'></script>
1212

13-
<!-- libdot js files under test; keep in dep order -->
14-
<script src='../js/lib.js'></script>
15-
<script src='../js/lib_polyfill.js'></script>
16-
<script src='../js/lib_codec.js'></script>
17-
<script src='../js/lib_f.js'></script>
18-
<script src='../js/lib_colors.js'></script>
19-
<script src='../js/lib_event.js'></script>
20-
<script src='../js/lib_i18n.js'></script>
21-
<script src='../js/lib_message_manager.js'></script>
22-
<script src='../js/lib_storage.js'></script>
23-
<script src='../js/lib_storage_chrome.js'></script>
24-
<script src='../js/lib_storage_local.js'></script>
25-
<script src='../js/lib_storage_memory.js'></script>
26-
<script src='../js/lib_storage_terminal_private.js'></script>
27-
<script src='../js/lib_preference_manager.js'></script>
28-
2913
<!-- libdot js tests -->
3014
<script type='module' src='../js/lib_codec_tests.js'></script>
3115
<script type='module' src='../js/lib_colors_tests.js'></script>

libdot/index.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2012 The ChromiumOS Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
/**
6+
* @fileoverview libdot main library entry point.
7+
* @suppress {moduleLoad} Don't try and load dist/js/libdot_resources.js.
8+
*/
9+
10+
import {lib} from './js/lib.js';
11+
import './js/lib_polyfill.js';
12+
import './js/lib_codec.js';
13+
import './js/lib_colors.js';
14+
import './js/lib_event.js';
15+
import './js/lib_f.js';
16+
import './js/lib_i18n.js';
17+
import './js/lib_message_manager.js';
18+
import './js/lib_preference_manager.js';
19+
import './js/lib_resource.js';
20+
import './js/lib_storage.js';
21+
import './js/lib_storage_chrome.js';
22+
import './js/lib_storage_local.js';
23+
import './js/lib_storage_memory.js';
24+
import './js/lib_storage_terminal_private.js';
25+
import * as resources from './dist/js/libdot_resources.js';
26+
export {lib};
27+
28+
lib.resource.add('libdot/changelog/version', 'text/plain', resources.version);
29+
lib.resource.add('libdot/changelog/date', 'text/plain', resources.gitDate);

libdot/js/deps_resources.shim.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
* @suppress {moduleLoad,undefinedVars} closure compiler can't handle this.
88
*/
99

10-
import pkg from '../package.json';
10+
import {gitDate, version} from '../package.json';
1111

12-
lib.resource.add('libdot/changelog/version', 'text/plain', pkg.version);
13-
lib.resource.add('libdot/changelog/date', 'text/plain', pkg.gitDate);
12+
export {
13+
gitDate as gitDate,
14+
version as version,
15+
};

libdot/js/lib.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
'use strict';
5+
/**
6+
* @fileoverview Core namespace.
7+
*/
68

9+
/** @const */
710
const lib = {};
811

912
/**
@@ -54,3 +57,5 @@ lib.notUndefined = function(value) {
5457
lib.assert(value !== undefined);
5558
return value;
5659
};
60+
61+
export {lib};

libdot/js/lib_codec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
'use strict';
5+
import {lib} from '../index.js';
66

77
/** @const */
88
lib.codec = {};

libdot/js/lib_codec_tests.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* @fileoverview Various codec test suites.
77
*/
88

9+
import {lib} from '../index.js';
10+
911
describe('lib_codec_tests.js', () => {
1012

1113
/**

0 commit comments

Comments
 (0)