From 24f1c8a244fdd331b85f660580b6f2138ba83a1d Mon Sep 17 00:00:00 2001 From: kpal Date: Wed, 31 Jul 2024 12:28:36 +0100 Subject: [PATCH 1/5] Updated linting rules --- .eslintrc.json | 37 +++++++++++++---------- index.js | 50 +++++++++++++++--------------- package-lock.json | 62 ++++++++++++++++++++++++++++++++++++++ package.json | 2 ++ rollup.config.mjs | 6 ++-- src/asset.js | 12 +++++--- src/assets.js | 28 ++++++++++------- src/assets/createScript.js | 9 +++--- src/assets/replace.js | 2 +- src/assets/upload.js | 4 +-- src/entities.js | 15 ++++----- src/entities/copy.js | 24 +++++++++------ src/entities/create.js | 4 +-- src/entities/delete.js | 4 +-- src/entities/duplicate.js | 4 +-- src/entities/paste.js | 39 ++++++++++++++---------- src/entities/references.js | 2 +- src/entities/reparent.js | 3 +- src/entities/scripts.js | 14 ++++----- src/entity.js | 5 +-- src/jobs.js | 1 + src/messenger.js | 3 +- src/polyfills.js | 9 ++++-- src/realtime.js | 5 +-- src/realtime/asset.js | 2 +- src/realtime/assets.js | 3 +- src/realtime/connection.js | 3 +- src/realtime/scene.js | 2 +- src/realtime/scenes.js | 3 +- src/schema.js | 4 +-- src/schema/assets.js | 14 ++++----- src/schema/components.js | 8 ++--- src/selection.js | 3 +- src/settings.js | 1 + src/settings/scene.js | 1 + src/utils.js | 12 +++++--- tsconfig.json | 5 ++- 37 files changed, 257 insertions(+), 148 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index ce45be8..55912b1 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,6 +1,8 @@ { "extends": [ - "@playcanvas/eslint-config" + "@playcanvas/eslint-config", + "eslint:recommended", + "plugin:regexp/recommended" ], "globals": { "share": "readonly" @@ -15,21 +17,24 @@ "requireConfigFile": false }, "rules": { - "indent": [ - "error", - 4, - { - "FunctionExpression": { - "body": 1, - "parameters": 2 - }, - "MemberExpression": 0, - "SwitchCase": 1 - } - ], - "jsdoc/check-tag-names": ["error", { - "definedTags": ["category"] + "accessor-pairs": ["error", { "setWithoutGet": false, "getWithoutSet": false }], + "curly": ["error", "multi-line"], + "import/order": ["error", { + "groups": ["builtin", "external", "internal", ["parent", "sibling"], "index", "unknown"], + "newlines-between": "always", + "alphabetize": { "order": "asc", "caseInsensitive": true } }], - "jsdoc/check-examples": "off" + "indent": ["error", 4, { + "FunctionExpression": { "body": 1, "parameters": 2 }, + "MemberExpression": 0, + "SwitchCase": 1 + }], + "jsdoc/check-tag-names": ["error", { "definedTags": ["category"] }], + "jsdoc/check-examples": "off", + "no-prototype-builtins": "off", + "no-use-before-define": "off", + "prefer-arrow-callback": ["error", { "allowNamedFunctions": true }], + "prefer-template": "error", + "require-atomic-updates": "warn" } } diff --git a/index.js b/index.js index f09ce81..ae483aa 100644 --- a/index.js +++ b/index.js @@ -9,28 +9,28 @@ * @module Editor */ -export * from './src/polyfills'; -export * from './src/globals'; -export * from './src/utils'; -export * from './src/guid'; -export * from './src/entities'; -export * from './src/entity'; -export * from './src/assets'; -export * from './src/asset'; -export * from './src/settings'; -export * from './src/settings/scene'; -export * from './src/history'; -export * from './src/selection'; -export * from './src/schema'; -export * from './src/schema/components'; -export * from './src/schema/assets'; -export * from './src/realtime/connection'; -export * from './src/realtime/scene'; -export * from './src/realtime/scenes'; -export * from './src/realtime/asset'; -export * from './src/realtime/assets'; -export * from './src/realtime'; -export * from './src/messenger'; -export * from './src/jobs'; -export * from './src/localstorage'; -export * from './src/clipboard'; +export * from './src/polyfills.js'; +export * from './src/globals.js'; +export * from './src/utils.js'; +export * from './src/guid.js'; +export * from './src/entities.js'; +export * from './src/entity.js'; +export * from './src/assets.js'; +export * from './src/asset.js'; +export * from './src/settings.js'; +export * from './src/settings/scene.js'; +export * from './src/history.js'; +export * from './src/selection.js'; +export * from './src/schema.js'; +export * from './src/schema/components.js'; +export * from './src/schema/assets.js'; +export * from './src/realtime/connection.js'; +export * from './src/realtime/scene.js'; +export * from './src/realtime/scenes.js'; +export * from './src/realtime/asset.js'; +export * from './src/realtime/assets.js'; +export * from './src/realtime.js'; +export * from './src/messenger.js'; +export * from './src/jobs.js'; +export * from './src/localstorage.js'; +export * from './src/clipboard.js'; diff --git a/package-lock.json b/package-lock.json index a7e7118..4bf8703 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,8 @@ "@rollup/plugin-babel": "^6.0.4", "chai": "^4.4.1", "eslint": "^8.56.0", + "eslint-plugin-import": "^2.29.1", + "eslint-plugin-regexp": "^2.6.0", "karma": "^6.4.2", "karma-chrome-launcher": "^3.2.0", "karma-mocha": "2.0.1", @@ -3559,6 +3561,27 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", "dev": true }, + "node_modules/eslint-plugin-regexp": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-regexp/-/eslint-plugin-regexp-2.6.0.tgz", + "integrity": "sha512-FCL851+kislsTEQEMioAlpDuK5+E5vs0hi1bF8cFlPlHcEjeRhuAzEsGikXRreE+0j4WhW2uO54MqTjXtYOi3A==", + "dev": true, + "dependencies": { + "@eslint-community/eslint-utils": "^4.2.0", + "@eslint-community/regexpp": "^4.9.1", + "comment-parser": "^1.4.0", + "jsdoc-type-pratt-parser": "^4.0.0", + "refa": "^0.12.1", + "regexp-ast-analysis": "^0.7.1", + "scslre": "^0.3.0" + }, + "engines": { + "node": "^18 || >=20" + }, + "peerDependencies": { + "eslint": ">=8.44.0" + } + }, "node_modules/eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", @@ -5723,6 +5746,18 @@ "node": ">=8.10.0" } }, + "node_modules/refa": { + "version": "0.12.1", + "resolved": "https://registry.npmjs.org/refa/-/refa-0.12.1.tgz", + "integrity": "sha512-J8rn6v4DBb2nnFqkqwy6/NnTYMcgLA+sLr0iIO41qpv0n+ngb7ksag2tMRl0inb1bbO/esUwzW1vbJi7K0sI0g==", + "dev": true, + "dependencies": { + "@eslint-community/regexpp": "^4.8.0" + }, + "engines": { + "node": "^12.0.0 || ^14.0.0 || >=16.0.0" + } + }, "node_modules/regenerate": { "version": "1.4.2", "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.2.tgz", @@ -5756,6 +5791,19 @@ "@babel/runtime": "^7.8.4" } }, + "node_modules/regexp-ast-analysis": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/regexp-ast-analysis/-/regexp-ast-analysis-0.7.1.tgz", + "integrity": "sha512-sZuz1dYW/ZsfG17WSAG7eS85r5a0dDsvg+7BiiYR5o6lKCAtUrEwdmRmaGF6rwVj3LcmAeYkOWKEPlbPzN3Y3A==", + "dev": true, + "dependencies": { + "@eslint-community/regexpp": "^4.8.0", + "refa": "^0.12.1" + }, + "engines": { + "node": "^12.0.0 || ^14.0.0 || >=16.0.0" + } + }, "node_modules/regexp.prototype.flags": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.1.tgz", @@ -6021,6 +6069,20 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "dev": true }, + "node_modules/scslre": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/scslre/-/scslre-0.3.0.tgz", + "integrity": "sha512-3A6sD0WYP7+QrjbfNA2FN3FsOaGGFoekCVgTyypy53gPxhbkCIjtO6YWgdrfM+n/8sI8JeXZOIxsHjMTNxQ4nQ==", + "dev": true, + "dependencies": { + "@eslint-community/regexpp": "^4.8.0", + "refa": "^0.12.0", + "regexp-ast-analysis": "^0.7.0" + }, + "engines": { + "node": "^14.0.0 || >=16.0.0" + } + }, "node_modules/semver": { "version": "6.3.1", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", diff --git a/package.json b/package.json index 0c4dbf5..7f4cd8b 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,8 @@ "@rollup/plugin-babel": "^6.0.4", "chai": "^4.4.1", "eslint": "^8.56.0", + "eslint-plugin-import": "^2.29.1", + "eslint-plugin-regexp": "^2.6.0", "karma": "^6.4.2", "karma-chrome-launcher": "^3.2.0", "karma-mocha": "2.0.1", diff --git a/rollup.config.mjs b/rollup.config.mjs index 96a2ceb..d28c7c3 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -1,5 +1,7 @@ -import babel from '@rollup/plugin-babel'; -import dts from 'rollup-plugin-dts'; +import { babel } from '@rollup/plugin-babel'; +import { dts } from 'rollup-plugin-dts'; + +import { runTsc } from './utils/plugins/rollup-run-tsc.mjs'; const umd = { external: ['@playcanvas/observer'], diff --git a/src/asset.js b/src/asset.js index b62b994..97ea33d 100644 --- a/src/asset.js +++ b/src/asset.js @@ -1,6 +1,7 @@ -import { globals as api } from './globals.js'; import { Events, Observer, ObserverHistory } from '@playcanvas/observer'; + import { replace } from './assets/replace.js'; +import { globals as api } from './globals.js'; /** * Represents an Asset. @@ -391,7 +392,7 @@ class Asset extends Events { this._history = new ObserverHistory({ item: this._observer, - prefix: 'asset.' + this.get('id') + '.', + prefix: `asset.${this.get('id')}.`, history: api.history }); @@ -416,8 +417,9 @@ class Asset extends Events { } _onSet(path, value) { - if (this._suspendOnSet || !path.startsWith('file') || path.endsWith('.url') || !this.get('file')) + if (this._suspendOnSet || !path.startsWith('file') || path.endsWith('.url') || !this.get('file')) { return; + } this._suspendOnSet = true; @@ -523,9 +525,9 @@ class Asset extends Events { * Loads asset from the server without subscribing to realtime changes. */ async load() { - const response = await fetch('/api/assets/' + this.get('id') + '?branchId=' + api.branchId); + const response = await fetch(`/api/assets/${this.get('id')}?branchId=${api.branchId}`); if (!response.ok) { - throw new Error(response.status + ': ' + response.statusText); + throw new Error(`${response.status}: ${response.statusText}`); } const data = await response.json(); diff --git a/src/assets.js b/src/assets.js index 3b4f273..0329bab 100644 --- a/src/assets.js +++ b/src/assets.js @@ -1,10 +1,11 @@ -import { Asset } from './asset.js'; -import { globals as api } from './globals.js'; import { Events, ObserverList } from '@playcanvas/observer'; -import { uploadFile } from './assets/upload.js'; -import { createTemplate } from './assets/createTemplate.js'; + +import { Asset } from './asset.js'; import { createScript } from './assets/createScript.js'; +import { createTemplate } from './assets/createTemplate.js'; import { instantiateTemplates } from './assets/instantiateTemplates.js'; +import { uploadFile } from './assets/upload.js'; +import { globals as api } from './globals.js'; /** * Arguments passed when uploading an asset file. @@ -68,8 +69,9 @@ class Assets extends Events { index: 'id', sorted: (a, b) => { const f = (b._data.type === 'folder') - (a._data.type === 'folder'); - if (f !== 0) + if (f !== 0) { return f; + } if ((a._data.name || '').toLowerCase() > (b._data.name || '').toLowerCase()) { return 1; } else if ((a._data.name || '').toLowerCase() < (b._data.name || '').toLowerCase()) { @@ -234,8 +236,9 @@ class Assets extends Events { let pos = this._assets.positionNextClosest(asset._observer, (a, b) => { const f = (b._data.type === 'folder') - (a._data.type === 'folder'); - if (f !== 0) + if (f !== 0) { return f; + } if ((a === b ? oldName : (a._data.name || '').toLowerCase()) > name) { return 1; @@ -246,14 +249,17 @@ class Assets extends Events { }); - if (pos === -1 && (ind + 1) === this._assets.data.length) + if (pos === -1 && (ind + 1) === this._assets.data.length) { return; + } - if (ind !== -1 && (ind + 1 === pos) || (ind === pos)) + if (ind !== -1 && (ind + 1 === pos) || (ind === pos)) { return; + } - if (ind < pos) + if (ind < pos) { pos--; + } this._assets.move(asset._observer, pos); this.emit('move', asset, pos); @@ -450,7 +456,7 @@ class Assets extends Events { getAssetForScript(script) { return this.findOne((asset) => { return asset.get('type') === 'script' && - asset.has('data.scripts.' + script); + asset.has(`data.scripts.${script}`); }); } @@ -919,7 +925,7 @@ class Assets extends Events { }); if (!response.ok) { - throw new Error(response.status + ': ' + response.statusText); + throw new Error(`${response.status}: ${response.statusText}`); } assets.forEach(a => this.remove(a)); diff --git a/src/assets/createScript.js b/src/assets/createScript.js index 82a453d..d92990b 100644 --- a/src/assets/createScript.js +++ b/src/assets/createScript.js @@ -1,4 +1,4 @@ -const VALID_FILENAME = /^([^0-9.#<>$+%!`&='{}@\\/:*?"<>|\n])([^#<>$+%!`&='{}@\\/:*?"<>|\n])*$/i; +const VALID_FILENAME = /^[^0-9.#<>$+%!`&='{}@\\/:*?"|\n][^#<>$+%!`&='{}@\\/:*?"|\n]*$/; /** * Creates filename and script content from provided arguments. If the provide filename contains a '.mjs' @@ -16,13 +16,14 @@ function createScript(filename, text) { const tokens = []; const name = filename.slice(0, -3); const str = name.replace(/([^A-Z])([A-Z][^A-Z])/g, '$1 $2').replace(/([A-Z0-9]{2,})/g, ' $1'); - const parts = str.split(/(\s|\-|_|\.)/g); + const parts = str.split(/([\s\-_.])/); // filter valid tokens for (let i = 0; i < parts.length; i++) { parts[i] = parts[i].toLowerCase().trim(); - if (parts[i] && parts[i] !== '-' && parts[i] !== '_' && parts[i] !== '.') + if (parts[i] && parts[i] !== '-' && parts[i] !== '_' && parts[i] !== '.') { tokens.push(parts[i]); + } } if (tokens.length) { @@ -45,7 +46,7 @@ function createScript(filename, text) { } if (!filename) { - filename = scriptName + '.js'; + filename = `${scriptName}.js`; } if (!/.js$/i.test(filename)) { diff --git a/src/assets/replace.js b/src/assets/replace.js index 4b3fade..0a53046 100644 --- a/src/assets/replace.js +++ b/src/assets/replace.js @@ -1,5 +1,5 @@ -import { globals as api } from '../globals.js'; import { findAssetReferencesInComponents, updateReferences } from '../entities/references.js'; +import { globals as api } from '../globals.js'; import { utils } from '../utils.js'; const REGEX_MODEL_DATA_MAPPING = /^data\.mapping\.(\d+)\.material$/; diff --git a/src/assets/upload.js b/src/assets/upload.js index 5017706..a22d79c 100644 --- a/src/assets/upload.js +++ b/src/assets/upload.js @@ -90,7 +90,7 @@ async function uploadFile(data, settings = null, onProgress = null) { const form = createFormData(data, settings); if (data.id) { method = 'PUT'; - url = '/api/assets/' + data.id; + url = `/api/assets/${data.id}`; } else { appendCreateFields(form, data); method = 'POST'; @@ -168,7 +168,7 @@ async function uploadFile(data, settings = null, onProgress = null) { }); if (!response.ok) { - throw new Error(`${response.status}${response.error ? ': ' + response.error : ''}`); + throw new Error(`${response.status}${response.error ? `: ${response.error}` : ''}`); } return response.json; diff --git a/src/entities.js b/src/entities.js index 241e689..c6dbccc 100644 --- a/src/entities.js +++ b/src/entities.js @@ -1,15 +1,16 @@ -import { globals as api } from './globals.js'; -import { Entity } from './entity.js'; import { Events, ObserverList } from '@playcanvas/observer'; -import { createEntity } from './entities/create.js'; -import { pasteEntities } from './entities/paste.js'; -import { duplicateEntities } from './entities/duplicate.js'; + import { copyEntities } from './entities/copy.js'; -import { reparentEntities } from './entities/reparent.js'; +import { createEntity } from './entities/create.js'; import { deleteEntities } from './entities/delete.js'; +import { duplicateEntities } from './entities/duplicate.js'; +import { pasteEntities } from './entities/paste.js'; import { updateReferences } from './entities/references.js'; -import { wait } from './entities/wait.js'; +import { reparentEntities } from './entities/reparent.js'; import { addScript, removeScript } from './entities/scripts.js'; +import { wait } from './entities/wait.js'; +import { Entity } from './entity.js'; +import { globals as api } from './globals.js'; /** * Data to create new Entity diff --git a/src/entities/copy.js b/src/entities/copy.js index 58b269c..8fe29a1 100644 --- a/src/entities/copy.js +++ b/src/entities/copy.js @@ -58,7 +58,7 @@ function gatherDependencies(entity, data) { api.schema.components.list().forEach((component) => { const paths = api.schema.components.getFieldsOfType(component, 'asset'); paths.forEach((path) => { - ASSET_PATHS.push('components.' + component + '.' + path); + ASSET_PATHS.push(`components.${component}.${path}`); }); }); } @@ -83,9 +83,10 @@ function gatherDependencies(entity, data) { if (!obj) continue; for (const key in obj) { - var fullKey = parts[0] + '.' + key + '.' + parts[1]; - if (!entity.has(fullKey)) + var fullKey = `${parts[0]}.${key}.${parts[1]}`; + if (!entity.has(fullKey)) { continue; + } const assets = entity.get(fullKey); if (!assets) continue; @@ -137,7 +138,7 @@ function gatherDependencies(entity, data) { if (!asset) continue; // search for asset script attributes in script asset - const assetData = asset.get('data.scripts.' + key + '.attributes'); + const assetData = asset.get(`data.scripts.${key}.attributes`); if (!assetData) continue; for (const name in assetData) { @@ -182,22 +183,26 @@ function gatherDependencies(entity, data) { function sortEntities(entities) { entities.sort((a, b) => { let parentA = a.get('parent'); - if (!parentA) + if (!parentA) { return -1; + } parentA = api.entities.get(parentA); - if (!parentA) + if (!parentA) { return -1; + } const indA = parentA.get('children').indexOf(a.get('resource_id')); let parentB = b.get('parent'); - if (!parentB) + if (!parentB) { return 1; + } parentB = api.entities.get(parentB); - if (!parentB) + if (!parentB) { return -1; + } const indB = parentB.get('children').indexOf(b.get('resource_id')); @@ -263,8 +268,9 @@ function copyEntities(entities) { for (const key in selection) { // set parent of each copied entity to null - if (data.hierarchy[key]) + if (data.hierarchy[key]) { data.hierarchy[key].parent = null; + } } // save to local storage diff --git a/src/entities/create.js b/src/entities/create.js index b25e40d..997b892 100644 --- a/src/entities/create.js +++ b/src/entities/create.js @@ -1,5 +1,5 @@ -import { globals as api } from '../globals.js'; import { Entity } from '../entity.js'; +import { globals as api } from '../globals.js'; /** * Creates new entity and adds it to the hierarchy @@ -91,7 +91,7 @@ function createEntity(data, options = {}) { if (options.history && api.history) { api.history.add({ - name: 'new entity ' + entity.get('resource_id'), + name: `new entity ${entity.get('resource_id')}`, // undo new entity undo: () => { entity = entity.latest(); diff --git a/src/entities/delete.js b/src/entities/delete.js index c0d12a7..d297c15 100644 --- a/src/entities/delete.js +++ b/src/entities/delete.js @@ -1,5 +1,5 @@ -import { globals as api } from '../globals.js'; import { findEntityReferencesInComponents, updateReferences } from './references.js'; +import { globals as api } from '../globals.js'; const USE_BACKEND_LIMIT = 500; @@ -91,7 +91,7 @@ async function deleteEntities(entities, options = {}) { // make sure we are not deleting root entities.forEach((e) => { if (e === api.entities.root) { - throw new Error('Cannot delete root entity ' + e.get('resource_id')); + throw new Error(`Cannot delete root entity ${e.get('resource_id')}`); } }); diff --git a/src/entities/duplicate.js b/src/entities/duplicate.js index 487c4a1..87142e2 100644 --- a/src/entities/duplicate.js +++ b/src/entities/duplicate.js @@ -1,5 +1,5 @@ -import { globals as api } from '../globals.js'; import { findEntityReferencesInComponents, updateReferences } from './references.js'; +import { globals as api } from '../globals.js'; import { Guid } from '../guid.js'; /** @typedef {import("../entity").Entity} Entity */ @@ -147,7 +147,7 @@ function duplicateEntity(entity, parent, ind, duplicatedIdsMap, useUniqueName) { } // add children too - children.forEach(function (childId) { + children.forEach((childId) => { duplicateEntity(api.entities.get(childId), entity, undefined, duplicatedIdsMap); }); diff --git a/src/entities/paste.js b/src/entities/paste.js index c9b028d..e29cb34 100644 --- a/src/entities/paste.js +++ b/src/entities/paste.js @@ -1,5 +1,6 @@ -import { globals as api } from '../globals.js'; import { Observer } from '@playcanvas/observer'; + +import { globals as api } from '../globals.js'; import { Guid } from '../guid.js'; const USE_BACKEND_LIMIT = 500; @@ -25,8 +26,9 @@ function remapAsset(assetId, assetsIndex) { let result = parseInt(assetId, 10); const assetData = assetsIndex[assetId]; - if (!assetData) + if (!assetData) { return result; + } const len = assetData.path.length; const name = assetData.path[len - 1]; @@ -49,8 +51,9 @@ function remapAsset(assetId, assetsIndex) { } } - if (!folder) + if (!folder) { return result; + } pathToId.push(parseInt(folder.get('id'), 10)); } @@ -76,8 +79,9 @@ function remapAsset(assetId, assetsIndex) { } } - if (!pathsEqual) + if (!pathsEqual) { continue; + } } result = parseInt(asset.get('id'), 10); @@ -105,7 +109,7 @@ function remapField(entity, path, mapping, sameProject) { if (!obj) return; for (const key in obj) { - const fullKey = parts[0] + '.' + key + '.' + parts[1]; + const fullKey = `${parts[0]}.${key}.${parts[1]}`; if (!entity.has(fullKey)) continue; const value = entity.get(fullKey); @@ -210,7 +214,7 @@ function remapEntitiesAndAssets(entity, parent, data, entityMapping, assetMappin api.schema.components.list().forEach((component) => { const paths = api.schema.components.getFieldsOfType(component, 'asset'); paths.forEach((path) => { - ASSET_PATHS.push('components.' + component + '.' + path); + ASSET_PATHS.push(`components.${component}.${path}`); }); }); } @@ -243,27 +247,29 @@ function remapEntitiesAndAssets(entity, parent, data, entityMapping, assetMappin if (attr.value) { if (attr.value instanceof Array) { for (let j = 0; j < attr.value.length; j++) { - entity.set('components.script.scripts.' + i + '.attributes.' + name + '.value.' + j, mapValue(attr.value[j], assetMapping, sameProject)); + entity.set(`components.script.scripts.${i}.attributes.${name}.value.${j}`, mapValue(attr.value[j], assetMapping, sameProject)); } } else { - entity.set('components.script.scripts.' + i + '.attributes.' + name + '.value', mapValue(attr.value, assetMapping, sameProject)); + entity.set(`components.script.scripts.${i}.attributes.${name}.value`, mapValue(attr.value, assetMapping, sameProject)); } } if (attr.defaultValue) { if (attr.defaultValue instanceof Array) { for (let j = 0; j < attr.defaultValue.length; j++) { - entity.set('components.script.scripts.' + i + '.attributes.' + name + '.defaultValue.' + j, mapValue(attr.value[j], assetMapping, sameProject)); + entity.set(`components.script.scripts.${i}.attributes.${name}.defaultValue.${j}`, mapValue(attr.value[j], assetMapping, sameProject)); } } else { - entity.set('components.script.scripts.' + i + '.attributes.' + name + '.defaultValue', mapValue(attr.value, assetMapping, sameProject)); + entity.set(`components.script.scripts.${i}.attributes.${name}.defaultValue`, mapValue(attr.value, assetMapping, sameProject)); } } } else if (attr.type === 'entity') { - if (entityMapping[attr.value]) - entity.set('components.script.scripts.' + i + '.attributes.' + name + '.value', mapValue(attr.value, entityMapping, sameProject)); - if (entityMapping[attr.defaultValue]) - entity.set('components.script.scripts.' + i + '.attributes.' + name + '.defaultValue', mapValue(attr.defaultValue, entityMapping, sameProject)); + if (entityMapping[attr.value]) { + entity.set(`components.script.scripts.${i}.attributes.${name}.value`, mapValue(attr.value, entityMapping, sameProject)); + } + if (entityMapping[attr.defaultValue]) { + entity.set(`components.script.scripts.${i}.attributes.${name}.defaultValue`, mapValue(attr.defaultValue, entityMapping, sameProject)); + } } } } @@ -278,7 +284,7 @@ function remapEntitiesAndAssets(entity, parent, data, entityMapping, assetMappin if (!attrs) continue; for (const key in attrs) { - const attrData = asset.get('data.scripts.' + script + '.attributes.' + key); + const attrData = asset.get(`data.scripts.${script}.attributes.${key}`); if (attrData) { // handle json script attributes if (attrData.type === 'json' && Array.isArray(attrData.schema)) { @@ -519,8 +525,9 @@ async function pasteEntities(parent, options = {}) { select: false }); - if (select) + if (select) { selectedEntities.push(entity); + } } if (selectedEntities.length) { diff --git a/src/entities/references.js b/src/entities/references.js index ca57735..b8129ed 100644 --- a/src/entities/references.js +++ b/src/entities/references.js @@ -38,7 +38,7 @@ function findReferencesInComponents(entity, refType) { if (Array.isArray(value)) { value.forEach((id, i) => { if (id) { - addReference(entity, path + '.' + i, id); + addReference(entity, `${path}.${i}`, id); } }); } else { diff --git a/src/entities/reparent.js b/src/entities/reparent.js index c1cb577..8b65811 100644 --- a/src/entities/reparent.js +++ b/src/entities/reparent.js @@ -44,8 +44,9 @@ function reparentEntities(data, options = {}) { const isValidRecord = (entity, parentOld, parent) => { const resourceId = entity.get('resource_id'); - if (parentOld.get('children').indexOf(resourceId) === -1 || (parent.get('children').indexOf(resourceId) !== -1 && parent !== parentOld)) + if (parentOld.get('children').indexOf(resourceId) === -1 || (parent.get('children').indexOf(resourceId) !== -1 && parent !== parentOld)) { return false; + } // check if not reparenting to own child let deny = false; diff --git a/src/entities/scripts.js b/src/entities/scripts.js index e1cd253..4d4b285 100644 --- a/src/entities/scripts.js +++ b/src/entities/scripts.js @@ -1,7 +1,7 @@ import { globals as api } from '../globals.js'; async function addScript(entities, scriptName, options) { - entities = entities.filter(e => !e.has('components.script.scripts.' + scriptName)); + entities = entities.filter(e => !e.has(`components.script.scripts.${scriptName}`)); if (!entities.length) return; const addedComponentsTo = new Set(); @@ -72,7 +72,7 @@ async function addScript(entities, scriptName, options) { }); // wait for messenger response - api.messenger.once('scriptAttrsFinished:' + jobId, (msg) => { + api.messenger.once(`scriptAttrsFinished:${jobId}`, (msg) => { api.jobs.finish(jobId)(msg); }); @@ -82,7 +82,7 @@ async function addScript(entities, scriptName, options) { entities = entities.slice(); api.history.add({ - name: 'entities.components.script.scripts.' + scriptName, + name: `entities.components.script.scripts.${scriptName}`, redo: () => { const newOptions = Object.assign({}, options); newOptions.history = false; @@ -128,7 +128,7 @@ function removeScript(entities, scriptName, options) { prevIndex = order.indexOf(scriptName); } - const prevScript = entity.get('components.script.scripts.' + scriptName); + const prevScript = entity.get(`components.script.scripts.${scriptName}`); prev[entity.get('resource_id')] = { prevIndex, prevScript }; }); @@ -140,14 +140,14 @@ function removeScript(entities, scriptName, options) { entities.forEach((entity) => { const historyEnabled = entity.history.enabled; entity.history.enabled = false; - entity.unset('components.script.scripts.' + scriptName); + entity.unset(`components.script.scripts.${scriptName}`); entity.removeValue('components.script.order', scriptName); entity.history.enabled = historyEnabled; }); if (api.history && history) { api.history.add({ - name: 'entities.components.script.scripts.' + scriptName, + name: `entities.components.script.scripts.${scriptName}`, undo: () => { entities = entities.map(e => e.latest()).filter(e => e && e.has('components.script') && prev[e.get('resource_id')]); @@ -175,7 +175,7 @@ function removeScript(entities, scriptName, options) { prevIndex = order.indexOf(scriptName); } - const prevScript = entity.get('components.script.scripts.' + scriptName); + const prevScript = entity.get(`components.script.scripts.${scriptName}`); prev[entity.get('resource_id')] = { prevIndex, prevScript }; }); diff --git a/src/entity.js b/src/entity.js index 1cfcfe9..d5f968a 100644 --- a/src/entity.js +++ b/src/entity.js @@ -1,5 +1,6 @@ -import { globals as api } from './globals.js'; import { Events, Observer, ObserverHistory } from '@playcanvas/observer'; + +import { globals as api } from './globals.js'; import { Guid } from './guid.js'; /** @@ -488,7 +489,7 @@ class Entity extends Events { this._history = new ObserverHistory({ item: this._observer, - prefix: 'entity.' + this.get('resource_id') + '.', + prefix: `entity.${this.get('resource_id')}.`, history: api.history }); this._observer.history = this._history; diff --git a/src/jobs.js b/src/jobs.js index 5a12d33..3d487f4 100644 --- a/src/jobs.js +++ b/src/jobs.js @@ -1,4 +1,5 @@ import { Events } from '@playcanvas/observer'; + import { Guid } from './guid.js'; /** diff --git a/src/messenger.js b/src/messenger.js index a78aecc..14c8ffc 100644 --- a/src/messenger.js +++ b/src/messenger.js @@ -1,6 +1,7 @@ -import { globals as api } from './globals.js'; import { Events } from '@playcanvas/observer'; +import { globals as api } from './globals.js'; + /** * The Messenger API. The messenger receives messages * when various things happen e.g. an asset is created etc. diff --git a/src/polyfills.js b/src/polyfills.js index d74f00d..c6dc18c 100644 --- a/src/polyfills.js +++ b/src/polyfills.js @@ -3,16 +3,19 @@ if (!Array.prototype.equals) { Object.defineProperty(Array.prototype, 'equals', { enumerable: false, value: function (array) { - if (!array) + if (!array) { return false; + } - if (this.length !== array.length) + if (this.length !== array.length) { return false; + } for (var i = 0, l = this.length; i < l; i++) { if (this[i] instanceof Array && array[i] instanceof Array) { - if (!this[i].equals(array[i])) + if (!this[i].equals(array[i])) { return false; + } } else if (this[i] !== array[i]) { return false; } diff --git a/src/realtime.js b/src/realtime.js index 9bb23ec..b0fbe99 100644 --- a/src/realtime.js +++ b/src/realtime.js @@ -1,7 +1,8 @@ +import { Events } from '@playcanvas/observer'; + +import { RealtimeAssets } from './realtime/assets.js'; import { RealtimeConnection } from './realtime/connection.js'; import { RealtimeScenes } from './realtime/scenes.js'; -import { RealtimeAssets } from './realtime/assets.js'; -import { Events } from '@playcanvas/observer'; /** * Provides methods to communicate and load / save data to the realtime server diff --git a/src/realtime/asset.js b/src/realtime/asset.js index fef96c6..f532bdd 100644 --- a/src/realtime/asset.js +++ b/src/realtime/asset.js @@ -99,7 +99,7 @@ class RealtimeAsset extends Events { _onLoad() { const assetData = this._document.data; if (!assetData) { - const err = 'Could not load asset: ' + this._uniqueId; + const err = `Could not load asset: ${this._uniqueId}`; this._onError(err); this.unload(); this.emit('error:load', err); diff --git a/src/realtime/assets.js b/src/realtime/assets.js index fbfd75b..ef3e749 100644 --- a/src/realtime/assets.js +++ b/src/realtime/assets.js @@ -1,6 +1,7 @@ -import { RealtimeAsset } from './asset.js'; import { Events } from '@playcanvas/observer'; +import { RealtimeAsset } from './asset.js'; + /** * Provides methods to load assets from sharedb * diff --git a/src/realtime/connection.js b/src/realtime/connection.js index 825e67b..bd1c6cd 100644 --- a/src/realtime/connection.js +++ b/src/realtime/connection.js @@ -1,6 +1,7 @@ -import { globals as api } from '../globals.js'; import { Events } from '@playcanvas/observer'; +import { globals as api } from '../globals.js'; + const RECONNECT_INTERVAL = 3; const MAX_ATTEMPTS = 3; diff --git a/src/realtime/scene.js b/src/realtime/scene.js index 230a3f1..21e929d 100644 --- a/src/realtime/scene.js +++ b/src/realtime/scene.js @@ -54,7 +54,7 @@ class RealtimeScene extends Events { this._document = null; this._loaded = false; - this._connection.send('close:scene:' + this._uniqueId); + this._connection.send(`close:scene:${this._uniqueId}`); this._evtConnection.unbind(); this._evtConnection = null; diff --git a/src/realtime/scenes.js b/src/realtime/scenes.js index 938ebff..c322a3c 100644 --- a/src/realtime/scenes.js +++ b/src/realtime/scenes.js @@ -1,6 +1,7 @@ -import { RealtimeScene } from './scene.js'; import { Events } from '@playcanvas/observer'; +import { RealtimeScene } from './scene.js'; + /** * Provides methods to load scenes from sharedb * diff --git a/src/schema.js b/src/schema.js index aa095ea..592bfb4 100644 --- a/src/schema.js +++ b/src/schema.js @@ -1,5 +1,5 @@ -import { ComponentSchema } from './schema/components.js'; import { AssetsSchema } from './schema/assets.js'; +import { ComponentSchema } from './schema/components.js'; /** * Provides methods to access the Editor schema. @@ -66,7 +66,7 @@ class Schema { } } - return 'array:' + this.getType(field[0]); + return `array:${this.getType(field[0])}`; } if (field.$type) { diff --git a/src/schema/assets.js b/src/schema/assets.js index 5ada3e2..c53df9c 100644 --- a/src/schema/assets.js +++ b/src/schema/assets.js @@ -22,7 +22,7 @@ class AssetsSchema { * @returns {object} The default data */ getDefaultData(type) { - const field = type + 'Data'; + const field = `${type}Data`; if (!field || !this._schema[field]) return null; @@ -57,7 +57,7 @@ class AssetsSchema { const recurse = (schemaField, path, prefix = '') => { if (!schemaField) return; - if (schemaField.$editorType === type || schemaField.$editorType === 'array:' + type) { + if (schemaField.$editorType === type || schemaField.$editorType === `array:${type}`) { result.push(prefix + path); return; } @@ -65,19 +65,19 @@ class AssetsSchema { for (const field in schemaField) { if (field.startsWith('$')) continue; - const p = (path ? path + '.' : '') + field; + const p = (path ? `${path}.` : '') + field; const fieldType = this._schemaApi.getType(schemaField[field]); - if (fieldType === type || fieldType === 'array:' + type) { + if (fieldType === type || fieldType === `array:${type}`) { result.push(prefix + p); } else if (fieldType === 'object' && schemaField[field].$of) { - recurse(schemaField[field].$of, p + '.*', prefix); + recurse(schemaField[field].$of, `${p}.*`, prefix); } else if (fieldType === 'array:object' && Array.isArray(schemaField[field].$type)) { - recurse(schemaField[field].$type[0], p + '.*', prefix); + recurse(schemaField[field].$type[0], `${p}.*`, prefix); } } }; - recurse(this._schema[assetType + 'Data'], '', 'data.'); + recurse(this._schema[`${assetType}Data`], '', 'data.'); return result; } diff --git a/src/schema/components.js b/src/schema/components.js index 6e4e550..ec14064 100644 --- a/src/schema/components.js +++ b/src/schema/components.js @@ -72,7 +72,7 @@ class ComponentSchema { const recurse = (schemaField, path) => { if (!schemaField) return; - if (schemaField.$editorType === type || schemaField.$editorType === 'array:' + type) { + if (schemaField.$editorType === type || schemaField.$editorType === `array:${type}`) { result.push(path); return; } @@ -80,12 +80,12 @@ class ComponentSchema { for (const field in schemaField) { if (field.startsWith('$')) continue; - const p = (path ? path + '.' : '') + field; + const p = (path ? `${path}.` : '') + field; const fieldType = this._schemaApi.getType(schemaField[field]); - if (fieldType === type || fieldType === 'array:' + type) { + if (fieldType === type || fieldType === `array:${type}`) { result.push(p); } else if (fieldType === 'object' && schemaField[field].$of) { - recurse(schemaField[field].$of, p + '.*'); + recurse(schemaField[field].$of, `${p}.*`); } } }; diff --git a/src/selection.js b/src/selection.js index 10838a1..36787a3 100644 --- a/src/selection.js +++ b/src/selection.js @@ -1,6 +1,7 @@ -import { globals as api } from './globals.js'; import { Events } from '@playcanvas/observer'; +import { globals as api } from './globals.js'; + /** * Enables undo / redo of selection changes */ diff --git a/src/settings.js b/src/settings.js index 867629b..a26b0b0 100644 --- a/src/settings.js +++ b/src/settings.js @@ -1,4 +1,5 @@ import { Events } from '@playcanvas/observer'; + import { SceneSettings } from './settings/scene.js'; /** diff --git a/src/settings/scene.js b/src/settings/scene.js index ee67f07..588b961 100644 --- a/src/settings/scene.js +++ b/src/settings/scene.js @@ -1,4 +1,5 @@ import { Events, Observer, ObserverHistory } from '@playcanvas/observer'; + import { globals as api } from '../globals.js'; /** diff --git a/src/utils.js b/src/utils.js index 96cb027..d3e8734 100644 --- a/src/utils.js +++ b/src/utils.js @@ -11,8 +11,9 @@ class utils { * @returns {object} A copy of the data */ static deepCopy(data) { - if (data == null || typeof data !== 'object') + if (data == null || typeof data !== 'object') { return data; + } if (data instanceof Array) { var arr = []; @@ -24,8 +25,9 @@ class utils { const obj = {}; for (const key in data) { - if (data.hasOwnProperty(key)) + if (data.hasOwnProperty(key)) { obj[key] = this.deepCopy(data[key]); + } } return obj; } @@ -36,7 +38,7 @@ class utils { function process(item, key) { let current = item; - let p = (pathSoFar ? pathSoFar + '.' : '') + key; + let p = (pathSoFar ? `${pathSoFar}.` : '') + key; for (let i = startIndex; i < pathParts.length; i++) { // if we found another star recurse if (pathParts[i] === '*') { @@ -58,7 +60,7 @@ class utils { return; } - p += '.' + pathParts[i]; + p += `.${pathParts[i]}`; } // call callback with the path we've found so far @@ -104,7 +106,7 @@ class utils { let i; for (i = 1; i < parts.length; i++) { if (parts[i] === '*') break; - firstPartialPath += '.' + parts[i]; + firstPartialPath += `.${parts[i]}`; } if (!obj.has(firstPartialPath)) return; diff --git a/tsconfig.json b/tsconfig.json index 10b0617..de03147 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,7 +13,6 @@ "sourceMap": true, "moduleResolution": "node" }, - "include": [ - "**/*.js", - ] + "include": ["**/*.js"], + "exclude": ["dist/*"] } From 1478af4b70ee60f5ac4a539f560fe2f2b4103390 Mon Sep 17 00:00:00 2001 From: kpal Date: Wed, 31 Jul 2024 12:31:45 +0100 Subject: [PATCH 2/5] updated types building --- package.json | 2 +- rollup.config.mjs | 1 + tsconfig.build.json | 9 +++++++++ utils/plugins/rollup-run-tsc.mjs | 18 ++++++++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 tsconfig.build.json create mode 100644 utils/plugins/rollup-run-tsc.mjs diff --git a/package.json b/package.json index 7f4cd8b..19f39ea 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "test": "karma start test/karma.conf.js --single-run", "test:debug": "karma start test/karma.conf.js --single-run=false --browsers Chrome", "build": "rollup -c", - "build:types": "tsc index.js --outDir types --allowJs --declaration --emitDeclarationOnly && rollup -c --environment target:types", + "build:types": "rollup -c --environment target:types", "docs": "typedoc", "lint": "eslint --ext .js src" } diff --git a/rollup.config.mjs b/rollup.config.mjs index d28c7c3..1bc6821 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -62,6 +62,7 @@ const types = { format: 'es' }], plugins: [ + runTsc('tsconfig.build.json'), dts() ] }; diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..abf83fb --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,9 @@ +{ + "files": ["index.js"], + "compilerOptions": { + "allowJs": true, + "declaration": true, + "emitDeclarationOnly": true, + "outDir": "types" + } +} diff --git a/utils/plugins/rollup-run-tsc.mjs b/utils/plugins/rollup-run-tsc.mjs new file mode 100644 index 0000000..5804ed4 --- /dev/null +++ b/utils/plugins/rollup-run-tsc.mjs @@ -0,0 +1,18 @@ +import { execSync } from 'node:child_process'; +import * as fs from 'node:fs'; + +const GREEN_OUT = '\x1b[32m'; + +export function runTsc(config = 'tsconfig.json') { + if (!fs.existsSync(config)) { + throw new Error(`tsconfig file does not exist: ${config}`); + } + return { + name: 'run-tsc', + buildStart() { + const cmd = `tsc --project ${config}`; + console.log(`${GREEN_OUT}${cmd}`); + execSync(cmd); + } + }; +} From a14b294b0b0d0431498313966ea7ac2419c6237a Mon Sep 17 00:00:00 2001 From: kpal Date: Wed, 31 Jul 2024 12:37:24 +0100 Subject: [PATCH 3/5] moved index inside source --- index.js | 36 ------------------------------------ rollup.config.mjs | 4 ++-- src/index.js | 36 ++++++++++++++++++++++++++++++++++++ tsconfig.build.json | 2 +- tsconfig.json | 12 ++++++------ 5 files changed, 45 insertions(+), 45 deletions(-) delete mode 100644 index.js create mode 100644 src/index.js diff --git a/index.js b/index.js deleted file mode 100644 index ae483aa..0000000 --- a/index.js +++ /dev/null @@ -1,36 +0,0 @@ -/** - * The Editor module provides a comprehensive API for automating and extending - * the functionality of the PlayCanvas Editor. It allows developers to programmatically - * interact with the Editor, facilitating tasks such as scene manipulation, asset - * management, and custom tool integration. This module is essential for developers - * looking to streamline their workflow, create custom editing tools, or integrate - * external data and systems into the PlayCanvas Editor environment. - * - * @module Editor - */ - -export * from './src/polyfills.js'; -export * from './src/globals.js'; -export * from './src/utils.js'; -export * from './src/guid.js'; -export * from './src/entities.js'; -export * from './src/entity.js'; -export * from './src/assets.js'; -export * from './src/asset.js'; -export * from './src/settings.js'; -export * from './src/settings/scene.js'; -export * from './src/history.js'; -export * from './src/selection.js'; -export * from './src/schema.js'; -export * from './src/schema/components.js'; -export * from './src/schema/assets.js'; -export * from './src/realtime/connection.js'; -export * from './src/realtime/scene.js'; -export * from './src/realtime/scenes.js'; -export * from './src/realtime/asset.js'; -export * from './src/realtime/assets.js'; -export * from './src/realtime.js'; -export * from './src/messenger.js'; -export * from './src/jobs.js'; -export * from './src/localstorage.js'; -export * from './src/clipboard.js'; diff --git a/rollup.config.mjs b/rollup.config.mjs index 1bc6821..2282c0b 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -5,7 +5,7 @@ import { runTsc } from './utils/plugins/rollup-run-tsc.mjs'; const umd = { external: ['@playcanvas/observer'], - input: 'index.js', + input: 'src/index.js', output: { file: 'dist/index.js', format: 'umd', @@ -39,7 +39,7 @@ const umd = { const module = { external: ['@playcanvas/observer'], - input: 'index.js', + input: 'src/index.js', output: { file: 'dist/index.mjs', format: 'module', diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..1e8a73d --- /dev/null +++ b/src/index.js @@ -0,0 +1,36 @@ +/** + * The Editor module provides a comprehensive API for automating and extending + * the functionality of the PlayCanvas Editor. It allows developers to programmatically + * interact with the Editor, facilitating tasks such as scene manipulation, asset + * management, and custom tool integration. This module is essential for developers + * looking to streamline their workflow, create custom editing tools, or integrate + * external data and systems into the PlayCanvas Editor environment. + * + * @module Editor + */ + +export * from './polyfills.js'; +export * from './globals.js'; +export * from './utils.js'; +export * from './guid.js'; +export * from './entities.js'; +export * from './entity.js'; +export * from './assets.js'; +export * from './asset.js'; +export * from './settings.js'; +export * from './settings/scene.js'; +export * from './history.js'; +export * from './selection.js'; +export * from './schema.js'; +export * from './schema/components.js'; +export * from './schema/assets.js'; +export * from './realtime/connection.js'; +export * from './realtime/scene.js'; +export * from './realtime/scenes.js'; +export * from './realtime/asset.js'; +export * from './realtime/assets.js'; +export * from './realtime.js'; +export * from './messenger.js'; +export * from './jobs.js'; +export * from './localstorage.js'; +export * from './clipboard.js'; diff --git a/tsconfig.build.json b/tsconfig.build.json index abf83fb..39ca09d 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,5 +1,5 @@ { - "files": ["index.js"], + "files": ["src/index.js"], "compilerOptions": { "allowJs": true, "declaration": true, diff --git a/tsconfig.json b/tsconfig.json index de03147..32555e3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,18 +1,18 @@ { "compilerOptions": { - "noImplicitAny": true, "allowJs": true, - "target": "es6", + "esModuleInterop" : true, "jsx": "react", "lib": [ "es2019", "dom", "dom.iterable" ], - "esModuleInterop" : true, + "moduleResolution": "node", + "noImplicitAny": true, + "outDir": "types", "sourceMap": true, - "moduleResolution": "node" + "target": "es6", }, - "include": ["**/*.js"], - "exclude": ["dist/*"] + "include": ["src/**/*.js", "test/**/*.js", "rollup.config.js"], } From fafec0bc5a2748882f780f4310d8b31ffa87befa Mon Sep 17 00:00:00 2001 From: kpal Date: Wed, 31 Jul 2024 12:37:50 +0100 Subject: [PATCH 4/5] updated eslint to include mjs files --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 19f39ea..454fd55 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,6 @@ "build": "rollup -c", "build:types": "rollup -c --environment target:types", "docs": "typedoc", - "lint": "eslint --ext .js src" + "lint": "eslint --ext .js,.mjs src" } } From 38e4f545028f8185b8dfe2fe84fe305091995968 Mon Sep 17 00:00:00 2001 From: kpal Date: Wed, 31 Jul 2024 13:41:39 +0100 Subject: [PATCH 5/5] removed global share and replaced with nodemodule --- .eslintrc.json | 3 - package-lock.json | 494 +++++++++++++++++++++++++++++++++++++ package.json | 5 + rollup.config.mjs | 13 +- src/realtime/connection.js | 1 + 5 files changed, 512 insertions(+), 4 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 55912b1..ed65821 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -4,9 +4,6 @@ "eslint:recommended", "plugin:regexp/recommended" ], - "globals": { - "share": "readonly" - }, "parser": "@babel/eslint-parser", "parserOptions": { "ecmaVersion": 11, diff --git a/package-lock.json b/package-lock.json index 4bf8703..6d7f8aa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,8 @@ "@playcanvas/eslint-config": "^1.7.1", "@playcanvas/observer": "1.3.2", "@rollup/plugin-babel": "^6.0.4", + "@rollup/plugin-commonjs": "^26.0.1", + "@rollup/plugin-node-resolve": "^15.2.3", "chai": "^4.4.1", "eslint": "^8.56.0", "eslint-plugin-import": "^2.29.1", @@ -24,8 +26,11 @@ "karma-mocha": "2.0.1", "karma-spec-reporter": "^0.0.36", "mocha": "^10.2.0", + "ot-text": "github:playcanvas/ot-text", "rollup": "^4.9.5", "rollup-plugin-dts": "^6.1.0", + "rollup-plugin-polyfill-node": "^0.13.0", + "sharedb": "^3.2.1", "sinon": "^17.0.1", "typedoc": "^0.25.12", "typedoc-plugin-mdn-links": "^3.1.18", @@ -1865,6 +1870,102 @@ "integrity": "sha512-6EwiSjwWYP7pTckG6I5eyFANjPhmPjUX9JRLUSfNPC7FX7zK9gyZAfUEaECL6ALTpGX5AjnBq3C9XmVWPitNpw==", "dev": true }, + "node_modules/@isaacs/cliui": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", + "integrity": "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==", + "dev": true, + "dependencies": { + "string-width": "^5.1.2", + "string-width-cjs": "npm:string-width@^4.2.0", + "strip-ansi": "^7.0.1", + "strip-ansi-cjs": "npm:strip-ansi@^6.0.1", + "wrap-ansi": "^8.1.0", + "wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@isaacs/cliui/node_modules/ansi-regex": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", + "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" + } + }, + "node_modules/@isaacs/cliui/node_modules/ansi-styles": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", + "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/@isaacs/cliui/node_modules/emoji-regex": { + "version": "9.2.2", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", + "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", + "dev": true + }, + "node_modules/@isaacs/cliui/node_modules/string-width": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", + "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", + "dev": true, + "dependencies": { + "eastasianwidth": "^0.2.0", + "emoji-regex": "^9.2.2", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@isaacs/cliui/node_modules/strip-ansi": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", + "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dev": true, + "dependencies": { + "ansi-regex": "^6.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" + } + }, + "node_modules/@isaacs/cliui/node_modules/wrap-ansi": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz", + "integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==", + "dev": true, + "dependencies": { + "ansi-styles": "^6.1.0", + "string-width": "^5.0.1", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz", @@ -1957,6 +2058,16 @@ "node": ">= 8" } }, + "node_modules/@pkgjs/parseargs": { + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", + "integrity": "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==", + "dev": true, + "optional": true, + "engines": { + "node": ">=14" + } + }, "node_modules/@playcanvas/eslint-config": { "version": "1.7.1", "resolved": "https://registry.npmjs.org/@playcanvas/eslint-config/-/eslint-config-1.7.1.tgz", @@ -2002,6 +2113,122 @@ } } }, + "node_modules/@rollup/plugin-commonjs": { + "version": "26.0.1", + "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-26.0.1.tgz", + "integrity": "sha512-UnsKoZK6/aGIH6AdkptXhNvhaqftcjq3zZdT+LY5Ftms6JR06nADcDsYp5hTU9E2lbJUEOhdlY5J4DNTneM+jQ==", + "dev": true, + "dependencies": { + "@rollup/pluginutils": "^5.0.1", + "commondir": "^1.0.1", + "estree-walker": "^2.0.2", + "glob": "^10.4.1", + "is-reference": "1.2.1", + "magic-string": "^0.30.3" + }, + "engines": { + "node": ">=16.0.0 || 14 >= 14.17" + }, + "peerDependencies": { + "rollup": "^2.68.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@rollup/plugin-commonjs/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/@rollup/plugin-commonjs/node_modules/glob": { + "version": "10.4.5", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.5.tgz", + "integrity": "sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg==", + "dev": true, + "dependencies": { + "foreground-child": "^3.1.0", + "jackspeak": "^3.1.2", + "minimatch": "^9.0.4", + "minipass": "^7.1.2", + "package-json-from-dist": "^1.0.0", + "path-scurry": "^1.11.1" + }, + "bin": { + "glob": "dist/esm/bin.mjs" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@rollup/plugin-commonjs/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@rollup/plugin-inject": { + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/@rollup/plugin-inject/-/plugin-inject-5.0.5.tgz", + "integrity": "sha512-2+DEJbNBoPROPkgTDNe8/1YXWcqxbN5DTjASVIOx8HS+pITXushyNiBV56RB08zuptzz8gT3YfkqriTBVycepg==", + "dev": true, + "dependencies": { + "@rollup/pluginutils": "^5.0.1", + "estree-walker": "^2.0.2", + "magic-string": "^0.30.3" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@rollup/plugin-node-resolve": { + "version": "15.2.3", + "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-15.2.3.tgz", + "integrity": "sha512-j/lym8nf5E21LwBT4Df1VD6hRO2L2iwUeUmP7litikRsVp1H6NWx20NEp0Y7su+7XGc476GnXXc4kFeZNGmaSQ==", + "dev": true, + "dependencies": { + "@rollup/pluginutils": "^5.0.1", + "@types/resolve": "1.20.2", + "deepmerge": "^4.2.2", + "is-builtin-module": "^3.2.1", + "is-module": "^1.0.0", + "resolve": "^1.22.1" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^2.78.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, "node_modules/@rollup/pluginutils": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.0.tgz", @@ -2279,6 +2506,12 @@ "undici-types": "~5.26.4" } }, + "node_modules/@types/resolve": { + "version": "1.20.2", + "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.20.2.tgz", + "integrity": "sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==", + "dev": true + }, "node_modules/@ungap/structured-clone": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", @@ -2507,6 +2740,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/arraydiff": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/arraydiff/-/arraydiff-0.1.3.tgz", + "integrity": "sha512-t0OgO06uolEcMUvV8+yHc9Pc9pazh8wi/Dtyok/sQwvcr8iFV+P86IfAzK7upUDhI4oavhVREMY7iSWtm38LeA==", + "dev": true + }, "node_modules/assertion-error": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", @@ -2516,6 +2755,15 @@ "node": "*" } }, + "node_modules/async": { + "version": "2.6.4", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz", + "integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==", + "dev": true, + "dependencies": { + "lodash": "^4.17.14" + } + }, "node_modules/available-typed-arrays": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz", @@ -2909,6 +3157,12 @@ "node": ">= 12.0.0" } }, + "node_modules/commondir": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", + "integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==", + "dev": true + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -3071,6 +3325,15 @@ "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", "dev": true }, + "node_modules/deepmerge": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.3.1.tgz", + "integrity": "sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/define-data-property": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.1.tgz", @@ -3160,6 +3423,12 @@ "void-elements": "^2.0.0" } }, + "node_modules/eastasianwidth": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", + "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==", + "dev": true + }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -4015,6 +4284,22 @@ "is-callable": "^1.1.3" } }, + "node_modules/foreground-child": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.2.1.tgz", + "integrity": "sha512-PXUUyLqrR2XCWICfv6ukppP96sdFwWbNEnfEMt7jNsISjMsvaLNinAHNDYyvkyU+SZG2BTSbT5NjG+vZslfGTA==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.0", + "signal-exit": "^4.0.1" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/fs-extra": { "version": "8.1.0", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", @@ -4304,6 +4589,15 @@ "node": ">= 0.4" } }, + "node_modules/hat": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/hat/-/hat-0.0.3.tgz", + "integrity": "sha512-zpImx2GoKXy42fVDSEad2BPKuSQdLcqsCYa48K3zHSzM/ugWuYjLDr8IXxpVuL7uCLHw56eaiLxCRthhOzf5ug==", + "dev": true, + "engines": { + "node": "*" + } + }, "node_modules/he": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", @@ -4566,6 +4860,12 @@ "node": ">=0.10.0" } }, + "node_modules/is-module": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-module/-/is-module-1.0.0.tgz", + "integrity": "sha512-51ypPSPCoTEIN9dy5Oy+h4pShgJmPCygKfyRCISBI+JoWT/2oJvK8QPxmwv7b/p239jXrm9M1mlQbyKJ5A152g==", + "dev": true + }, "node_modules/is-negative-zero": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.2.tgz", @@ -4620,6 +4920,15 @@ "node": ">=8" } }, + "node_modules/is-reference": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz", + "integrity": "sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==", + "dev": true, + "dependencies": { + "@types/estree": "*" + } + }, "node_modules/is-regex": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", @@ -4741,6 +5050,21 @@ "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "dev": true }, + "node_modules/jackspeak": { + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-3.4.3.tgz", + "integrity": "sha512-OGlZQpz2yfahA/Rd1Y8Cd9SIEsqvXkLVoSw/cgwhnhFMDbsQFeZYoJJ7bIZBS9BcamUW96asq/npPWugM+RQBw==", + "dev": true, + "dependencies": { + "@isaacs/cliui": "^8.0.2" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + }, + "optionalDependencies": { + "@pkgjs/parseargs": "^0.11.0" + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -5185,6 +5509,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/minipass": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz", + "integrity": "sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==", + "dev": true, + "engines": { + "node": ">=16 || 14 >=14.17" + } + }, "node_modules/mkdirp": { "version": "0.5.6", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", @@ -5522,6 +5855,17 @@ "node": ">= 0.8.0" } }, + "node_modules/ot-json0": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/ot-json0/-/ot-json0-1.1.0.tgz", + "integrity": "sha512-wf5fci7GGpMYRDnbbdIFQymvhsbFACMHtxjivQo5KgvAHlxekyfJ9aPsRr6YfFQthQkk4bmsl5yESrZwC/oMYQ==", + "dev": true + }, + "node_modules/ot-text": { + "version": "1.0.2", + "resolved": "git+ssh://git@github.com/playcanvas/ot-text.git#b3d5f9610f3a78a7782bbc3b466e1b88355d59e7", + "dev": true + }, "node_modules/p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", @@ -5552,6 +5896,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/package-json-from-dist": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.0.tgz", + "integrity": "sha512-dATvCeZN/8wQsGywez1mzHtTlP22H8OEfPrVMLNr4/eGa+ijtLn/6M5f0dY8UKNrC2O9UCU6SSoG3qRKnt7STw==", + "dev": true + }, "node_modules/parent-module": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", @@ -5606,6 +5956,28 @@ "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", "dev": true }, + "node_modules/path-scurry": { + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.11.1.tgz", + "integrity": "sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==", + "dev": true, + "dependencies": { + "lru-cache": "^10.2.0", + "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0" + }, + "engines": { + "node": ">=16 || 14 >=14.18" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/path-scurry/node_modules/lru-cache": { + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz", + "integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==", + "dev": true + }, "node_modules/path-to-regexp": { "version": "6.2.1", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.2.1.tgz", @@ -5985,6 +6357,18 @@ "typescript": "^4.5 || ^5.0" } }, + "node_modules/rollup-plugin-polyfill-node": { + "version": "0.13.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-polyfill-node/-/rollup-plugin-polyfill-node-0.13.0.tgz", + "integrity": "sha512-FYEvpCaD5jGtyBuBFcQImEGmTxDTPbiHjJdrYIp+mFIwgXiXabxvKUK7ZT9P31ozu2Tqm9llYQMRWsfvTMTAOw==", + "dev": true, + "dependencies": { + "@rollup/plugin-inject": "^5.0.4" + }, + "peerDependencies": { + "rollup": "^1.20.0 || ^2.0.0 || ^3.0.0 || ^4.0.0" + } + }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -6137,6 +6521,25 @@ "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", "dev": true }, + "node_modules/sharedb": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/sharedb/-/sharedb-3.2.1.tgz", + "integrity": "sha512-MuZVAmujwdM2CCrwEg7foKgC0j0bLCKyaULiiEZr+dQe0GUkUUgxhfMrNWhy4Vq6vjM8GmBYpRBmGDiGkajxzQ==", + "dev": true, + "dependencies": { + "arraydiff": "^0.1.1", + "async": "^2.6.3", + "fast-deep-equal": "^2.0.1", + "hat": "0.0.3", + "ot-json0": "^1.0.1" + } + }, + "node_modules/sharedb/node_modules/fast-deep-equal": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz", + "integrity": "sha512-bCK/2Z4zLidyB4ReuIsvALH6w31YfAQDmXMqMx6FyfHqvBxtjC0eRumeSu4Bs3XtXwpyIywtSTrVT99BxY1f9w==", + "dev": true + }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", @@ -6184,6 +6587,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/signal-exit": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", + "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", + "dev": true, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/sinon": { "version": "17.0.1", "resolved": "https://registry.npmjs.org/sinon/-/sinon-17.0.1.tgz", @@ -6340,6 +6755,21 @@ "node": ">=8" } }, + "node_modules/string-width-cjs": { + "name": "string-width", + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/string.prototype.trim": { "version": "1.2.8", "resolved": "https://registry.npmjs.org/string.prototype.trim/-/string.prototype.trim-1.2.8.tgz", @@ -6397,6 +6827,19 @@ "node": ">=8" } }, + "node_modules/strip-ansi-cjs": { + "name": "strip-ansi", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/strip-bom": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", @@ -6945,6 +7388,57 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, + "node_modules/wrap-ansi-cjs": { + "name": "wrap-ansi", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/wrap-ansi-cjs/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/wrap-ansi-cjs/node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/wrap-ansi-cjs/node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, "node_modules/wrap-ansi/node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", diff --git a/package.json b/package.json index 454fd55..78a33c5 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,8 @@ "@playcanvas/eslint-config": "^1.7.1", "@playcanvas/observer": "1.3.2", "@rollup/plugin-babel": "^6.0.4", + "@rollup/plugin-commonjs": "^26.0.1", + "@rollup/plugin-node-resolve": "^15.2.3", "chai": "^4.4.1", "eslint": "^8.56.0", "eslint-plugin-import": "^2.29.1", @@ -43,8 +45,11 @@ "karma-mocha": "2.0.1", "karma-spec-reporter": "^0.0.36", "mocha": "^10.2.0", + "ot-text": "github:playcanvas/ot-text", "rollup": "^4.9.5", "rollup-plugin-dts": "^6.1.0", + "rollup-plugin-polyfill-node": "^0.13.0", + "sharedb": "^3.2.1", "sinon": "^17.0.1", "typedoc": "^0.25.12", "typedoc-plugin-mdn-links": "^3.1.18", diff --git a/rollup.config.mjs b/rollup.config.mjs index 2282c0b..5dd640a 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -1,5 +1,8 @@ import { babel } from '@rollup/plugin-babel'; +import commonjs from '@rollup/plugin-commonjs'; +import resolve from '@rollup/plugin-node-resolve'; import { dts } from 'rollup-plugin-dts'; +import polyfills from 'rollup-plugin-polyfill-node'; import { runTsc } from './utils/plugins/rollup-run-tsc.mjs'; @@ -15,6 +18,9 @@ const umd = { } }, plugins: [ + commonjs(), + polyfills(), + resolve(), babel({ babelHelpers: 'bundled', babelrc: false, @@ -46,7 +52,12 @@ const module = { globals: { '@playcanvas/observer': 'observer' } - } + }, + plugins: [ + commonjs(), + polyfills(), + resolve() + ] }; const footer = `export as namespace api; diff --git a/src/realtime/connection.js b/src/realtime/connection.js index bd1c6cd..38fb031 100644 --- a/src/realtime/connection.js +++ b/src/realtime/connection.js @@ -1,6 +1,7 @@ import { Events } from '@playcanvas/observer'; import { globals as api } from '../globals.js'; +import { share } from '../sharedb.js'; const RECONNECT_INTERVAL = 3; const MAX_ATTEMPTS = 3;