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

-2
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

+1
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

+6-1
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

+12
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

-16
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

+29
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

+5-3
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

+6-1
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

+1-1
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

+2
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
/**

libdot/js/lib_colors.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
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';
6-
75
/**
86
* @fileoverview Color utilities.
97
*/
108

9+
import {lib} from '../index.js';
10+
1111
/** @const */
1212
lib.colors = {};
1313

libdot/js/lib_colors_tests.js

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* Verify color parsing logic.
99
*/
1010

11+
import {lib} from '../index.js';
12+
1113
describe('lib_color_tests.js', () => {
1214

1315
it('rgbToX11', () => {

libdot/js/lib_event.js

+1-1
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
/**
88
* An event is a JavaScript function with addListener and removeListener

libdot/js/lib_event_tests.js

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* @suppress {missingProperties} https://github.com/google/closure-compiler/issues/946
88
*/
99

10+
import {lib} from '../index.js';
11+
1012
describe('lib_event_tests.js', () => {
1113

1214
it('complete', () => {

libdot/js/lib_f.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
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';
6-
75
/**
86
* @fileoverview Grab bag of utility functions.
97
*/
108

9+
import {lib} from '../index.js';
10+
1111
/** @const */
1212
lib.f = {};
1313

libdot/js/lib_f_tests.js

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* @fileoverview Utility functions test suite.
77
*/
88

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

1113
it('replaceVars', () => {

libdot/js/lib_i18n.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
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';
6-
75
/**
86
* @fileoverview Wrappers over the browser i18n helpers.
97
*
108
* Arguably some of these functions should be l10n, but oh well.
119
*/
1210

11+
import {lib} from '../index.js';
12+
1313
/** @const */
1414
lib.i18n = {};
1515

libdot/js/lib_i18n_tests.js

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* @fileoverview i18n functions test suite.
77
*/
88

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

1113
/**

libdot/js/lib_message_manager.js

+1-1
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
/**
88
* MessageManager class handles internationalized strings.

libdot/js/lib_message_manager_tests.js

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* @fileoverview Message manager test suite.
77
*/
88

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

1113
/**

libdot/js/lib_polyfill.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
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';
6-
75
/**
86
* @fileoverview Polyfills for ES2020+ features we want to use.
97
* @suppress {duplicate} This file redefines many functions.
108
*/
119

10+
import {lib} from './lib.js';
11+
1212
/** @const */
1313
lib.polyfill = {};

libdot/js/lib_preference_manager.js

+1-1
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
/**
88
* Constructor for lib.PreferenceManager objects.

libdot/js/lib_preference_manager_tests.js

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* @fileoverview Unit tests for lib.PreferenceManager.
77
*/
88

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

1113
/**

libdot/js/lib_resource.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
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';
6-
75
/**
86
* @fileoverview Storage for canned resources.
97
*
@@ -14,6 +12,8 @@
1412
* collisions.
1513
*/
1614

15+
import {lib} from '../index.js';
16+
1717
/** @const */
1818
lib.resource = {};
1919

libdot/js/lib_storage.js

+1-1
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
/**
88
* Namespace for implementations of persistent, possibly cloud-backed

libdot/js/lib_storage_chrome.js

+1-1
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
/**
88
* chrome.storage based class with an async interface that is interchangeable

libdot/js/lib_storage_chrome_tests.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* @fileoverview Test suite for Chrome storage.
77
*/
88

9+
import {lib} from '../index.js';
910
import {storageApiTest} from './lib_storage_tests.js';
1011

1112
describe('lib_storage_chrome_tests.js', () => {

libdot/js/lib_storage_local.js

+1-1
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
/**
88
* window.localStorage based class with an async interface that is

libdot/js/lib_storage_local_tests.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* @fileoverview Test suite for local storage.
77
*/
88

9+
import {lib} from '../index.js';
910
import {storageApiTest} from './lib_storage_tests.js';
1011

1112
describe('lib_storage_local_tests.js', () => {

libdot/js/lib_storage_memory.js

+1-1
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
/**
88
* In-memory storage class with an async interface that is interchangeable with

libdot/js/lib_storage_memory_tests.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* @fileoverview Test suite for memory storage.
77
*/
88

9+
import {lib} from '../index.js';
910
import {storageApiTest} from './lib_storage_tests.js';
1011

1112
describe('lib_storage_memory_tests.js', () => {

libdot/js/lib_storage_terminal_private.js

+1-1
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
/**
88
* Storage implementation using chrome.terminalPrivate.

libdot/js/lib_storage_terminal_private_tests.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* @fileoverview Test suite for Terminal private storage.
77
*/
88

9+
import {lib} from '../index.js';
910
import {storageApiTest} from './lib_storage_tests.js';
1011

1112
describe('lib_storage_terminal_private_tests.js', () => {

libdot/js/lib_storage_tests.js

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* @fileoverview Common storage API tests.
77
*/
88

9+
import {lib} from '../index.js';
10+
911
/**
1012
* Testsuite for the generic storage API.
1113
*

0 commit comments

Comments
 (0)