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

[WIP] Convert to vanilla JavaScript modules (ES Modules) #183

Draft
wants to merge 18 commits into
base: mainline2.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
78199f6
fix for syntax regression in Oculus Browser
trusktr Aug 27, 2023
2999265
pin webpack dependency versions so they won't break, and we can updat…
trusktr Aug 27, 2023
2115732
Merge branch 'fix-broken-webpack-dependency' into fix-syntax-for-oculus
trusktr Aug 27, 2023
388317d
WIP convert to vanilla ESM, re-do this commit
trusktr Sep 6, 2023
a79d796
remove webpack config and update tests. Avoid using global THREE and …
trusktr Sep 6, 2023
12447a2
install missing dependency for npm start script
trusktr Oct 5, 2023
ff18836
relax the three.js peer dependency version, three.js versioning is a …
trusktr Oct 5, 2023
747003f
build **and** test during release, as a safety precaution
trusktr Oct 5, 2023
9e0708e
add a FIXME comment for prettier conflict with eslint
trusktr Oct 5, 2023
04ff310
update package-lock
trusktr Oct 5, 2023
934a8ef
update eslintrc to no longer list globals that we now import with ES …
trusktr Oct 5, 2023
ee0b16d
remove the indent rule from eslintrc, all formatting is handled by pr…
trusktr Oct 5, 2023
e088aeb
remove credentials
trusktr Oct 5, 2023
a92d934
rename demo-credentials.module.js back to demo-credentials.js
trusktr Oct 5, 2023
8adf65b
remove the last AWS global from eslintrc, ensure all examples `import…
trusktr Oct 5, 2023
f5b9a52
restore the start scripts, similar to what the webpack server was doing
trusktr Oct 5, 2023
f41abf0
update packages to type:module, simplified with only `main` fields (n…
trusktr Oct 5, 2023
f2f7aba
add scripts for specifically running integration tests, remove one la…
trusktr Oct 11, 2023
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
158 changes: 76 additions & 82 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,83 +1,77 @@
{
"extends": [
"airbnb",
"prettier",
"plugin:jasmine/recommended",
"plugin:compat/recommended"
],
"plugins": [
"prettier",
"jasmine"
],
"ignorePatterns": [
"dist/",
"docs_template/",
"docs/"
],
"parserOptions": {
"ecmaVersion": 2020
},
"globals": {
"atob": true,
"btoa": true,
"document": true,
"navigator": true,
"window": true,
"XMLHttpRequest": true,
"AWS": true,
"THREE": true,
"BABYLON": true,
"expectAsync": true
},
"rules": {
// Specific rule overrides can go here.
"indent": [
"error",
2,
{
"SwitchCase": 1
}
],
"no-var": "warn",
"no-tabs": "warn",
"func-names": "off",
"object-curly-spacing": "off",
"no-param-reassign": "off",
"no-mixed-operators": "off",
"no-bitwise": "off",
"max-len": "off",
"import/no-extraneous-dependencies": "off",
// Turning off import resolution checks because they cause linting to fail
// if linting is performend before the sub-packages in this monorepo have
// been built. We'll rely instead on Webpack to catch any import resolution
// problems.
"import/no-unresolved": "off",
"no-shadow": "off",
"no-plusplus": "off",
"no-underscore-dangle": [
"warn",
{
"allowAfterThis": true,
"allowAfterSuper": true
}
],
"spaced-comment": "off",
"arrow-parens": "off",
"no-trailing-spaces": "warn",
"no-console": "off",
"comma-dangle": "off",
"no-else-return": "off",
"no-unused-vars": "warn",
"class-methods-use-this": "off",
"prefer-const": "warn",
"consistent-return": "off",
"arrow-body-style": "off",
"no-use-before-define": "off",
"default-param-last": "off"
},
"env": {
"browser": true,
"node": true,
"jasmine": true
}
{
"extends": [
"airbnb",
"prettier",
"plugin:jasmine/recommended",
"plugin:compat/recommended"
],
"plugins": [
"prettier",
"jasmine"
],
"ignorePatterns": [
"dist/",
"docs_template/",
"docs/"
],
"parserOptions": {
"ecmaVersion": 2020
},
"globals": {
"atob": true,
"btoa": true,
"document": true,
"navigator": true,
"window": true,
"XMLHttpRequest": true,
"globalThis": true,
"expectAsync": true
},
"rules": {
// Specific rule overrides can go here.
"no-var": "warn",
"no-tabs": "warn",
"func-names": "off",
"object-curly-spacing": "off",
"no-param-reassign": "off",
"no-mixed-operators": "off",
"no-bitwise": "off",
"max-len": "off",
"import/no-extraneous-dependencies": "off",
// Turning off import resolution checks because they cause linting to fail
// if linting is performend before the sub-packages in this monorepo have
// been built. We'll rely instead on Webpack to catch any import resolution
// problems.
"import/no-unresolved": "off",
// Turn off default requirement for extensionless import specifiers,
// because that conflicts with vanilla ES Module compatibility.
"import/extensions": ["error", "always"], // TODO
"no-shadow": "off",
"no-plusplus": "off",
"no-underscore-dangle": [
"warn",
{
"allowAfterThis": true,
"allowAfterSuper": true
}
],
"spaced-comment": "off",
"arrow-parens": "off",
"no-trailing-spaces": "warn",
"no-console": "off",
"comma-dangle": "off",
"no-else-return": "off",
"no-unused-vars": "warn",
"class-methods-use-this": "off",
"prefer-const": "warn",
"consistent-return": "off",
"arrow-body-style": "off",
"no-use-before-define": "off",
"default-param-last": "off"
},
"env": {
"browser": true,
"node": true,
"jasmine": true
}
}
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@ npm-debug.log
build
build/
docs/
demo-credentials.js
**/dist/
.hot-reload/
15 changes: 10 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,14 @@ npm install

### Building

To build all packages in the repository, run:
The Host libraries work without a build. Only the Babylon Hosts library has a build step for generating type definition files, which is totally optional for use in TypeScript projects.

To run the build (which runs only the Babylon Host lib's type declaration build step), run:
```
npm run build
```
Distributable build artifacts will be generated into a `dist/` directory within each package folder.

Distributable build artifacts (type declaration files) will be generated into a `dist/` directory inside the Babylon Host lib.

### Testing

Expand All @@ -82,12 +85,14 @@ Example applications for Babylon.js can be found in the `packages/demos-babylon/

#### Unit Tests

If you've already built the packages, you can execute the unit tests for all packages using the command:
You can execute the unit tests for all packages using the command:
```
npm run test
npm test
```

Alternately, you can both build and run the unit tests with a single command:
Running the build is not necessary for running tests, as all source files as JavaScript modules that work as-is without transformation.

You can run both the Babylon build and the unit tests with a single command to ensure both work at the same time:
```
npm run build-test
```
Expand Down
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

Amazon Sumerian Hosts (Hosts) is an experimental open source project that aims to make it easy to create interactive animated 3D characters for Babylon.js, three.js, and other web 3D frameworks. It leverages AWS services including [Amazon Polly](https://aws.amazon.com/polly/) (text-to-speech) and [Amazon Lex](https://aws.amazon.com/lex/) (chatbot).

<!-- CONTINUE Update this after the Babylon fix -->
> **Compatibility**
>
> ⚠️ Hosts is currently compatible with **BabylonJS v4** (4.2.1+). There are know issues if you try to use Hosts with BabylonJS v5. If you would like to see support for BabylonJS v5 added, comment on [this enhancement request issue](https://github.com/aws-samples/amazon-sumerian-hosts/issues/155).
> ⚠️ Hosts is currently compatible with **BabylonJS v4** (4.2.1+). There are known issues if you try to use Hosts with BabylonJS v5. If you would like to see support for BabylonJS v5 added, comment on [this enhancement request issue](https://github.com/aws-samples/amazon-sumerian-hosts/issues/155).
>
> ✏️ Hosts have been tested with **Three.js v0.127.0**.

Expand Down Expand Up @@ -34,7 +35,7 @@ The easiest way to get started using the hosts is by using plugins we provide fo

Visit the [aws-tools-for-babylonjs-editor](https://github.com/aws-samples/aws-tools-for-babylonjs-editor/blob/main/README.md) repository for more details.

#### Using pre-built NPM modules
#### Using NPM modules

If you are creating applications outside of the Babylon.JS Editor, you can easily install the relevant Hosts module using NPM.

Expand All @@ -56,7 +57,20 @@ For full detail on the classes and methods available, see the [API Documentation

#### Building from source

Building from source is considered an advanced option. It is not recommended unless you need to heavily customize the core Hosts functionality. Instructions on how to build from source can be found in the [CONTRIBUTING](CONTRIBUTING.md) document.
Both the core Host lib and the Three.js Host lib do not have a build. You can
customize them by simply editing the .js files in your own fork, and simply
running a static server to run the apps.

The Babylon Host lib has a TypeScript build step *only* for creating output
type definitions from its .js files, and is otherwise not required for running
the Babylon demos: simply edit the JavaScript files, and start the static
server to run the demos.

If you need to build the type definitions for consumption in a TypeScript
project, then run `npm run build` at the root of the repo (after first running
`npm install` if you haven't already).

Find more details in [CONTRIBUTING](CONTRIBUTING.md).

## Demos

Expand Down
4 changes: 2 additions & 2 deletions demo-credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
// assigned to it:
// - AmazonPollyReadOnlyAccess
// - AmazonLexRunBotsOnly
const cognitoIdentityPoolId = 'us-west-2:xxxx-xxxx-xxxx-xxxx';
module.exports = cognitoIdentityPoolId;
// eslint-disable-next-line
export const cognitoIdentityPoolId = 'us-west-2:xxxx-xxxx-xxxx-xxxx';
15 changes: 7 additions & 8 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0

// We will use the core Webpack with a few changes for unit testing
const webpackConfig = require('./webpack.test');
// Removing the output will stop karma from outputing chunks for the test code
delete webpackConfig.output;

const TEST_BROWSERS =
process.env.TEST_BROWSERS !== undefined
? process.env.TEST_BROWSERS.split(',')
.map(s => s.trim())
.filter(s => s !== '')
.map(s => s.trim())
.filter(s => s !== '')
: ['Chrome'];
console.log(`TEST_BROWSERS=${TEST_BROWSERS.join(',')}`);

Expand All @@ -31,6 +26,10 @@ module.exports = function(config) {

plugins: [
'karma-jasmine',
// TODO We use karma-webpack so that JavaScript module import/export
// syntax works, but we might be able to instead make our own little
// plugin to call each entry point with native `import(0)`, and provide an
// `importmap` script in the HTML harness.
'karma-webpack',
'karma-firefox-launcher',
'karma-chrome-launcher',
Expand Down Expand Up @@ -96,7 +95,7 @@ module.exports = function(config) {
// how many browser should be started simultaneous
concurrency: Infinity,

webpack: webpackConfig,
webpack: {}, // Empty, no config needed.

webpackServer: {
noInfo: true,
Expand Down
Loading