Make worker files buildable (part 1)

This commit is contained in:
yflory 2024-10-11 15:41:08 +02:00
parent e40410eecb
commit 503a7a08b5
14 changed files with 1932 additions and 65 deletions

3
.gitignore vendored
View File

@ -32,6 +32,9 @@ www/common/onlyoffice/v*
/onlyoffice-conf/
/onlyoffice-dist/
_build
www/common/worker.bundle.js
# ---> Node
# Logs
logs

View File

@ -10,8 +10,8 @@
but you should not change it directly (/common/application_config_internal.js)
*/
define(['/common/application_config_internal.js'], function (AppConfig) {
(() => {
const factory = (AppConfig) => {
// Example: If you want to remove the survey link in the menu:
// AppConfig.surveyURL = "";
@ -19,4 +19,16 @@ define(['/common/application_config_internal.js'], function (AppConfig) {
//AppConfig.supportLanguages = [ 'en', 'fr' ];
return AppConfig;
});
};
// Do not change code below
if (typeof(module) !== 'undefined' && module.exports) {
module.exports = factory(
require('../www/common/application_config_internal.js')
);
} else if ((typeof(define) !== 'undefined' && define !== null) && (define.amd !== null)) {
define(['/common/application_config_internal.js'], factory);
}
})();

View File

@ -574,6 +574,7 @@ const ssoCfg = (SSOUtils && ssoList.length) ? {
list: ssoList
} : false;
var serveConfig = makeRouteCache(function () {
// NOTE: we may extract JSON from this config using slice(27, -5)
return [
'define(function(){',
'return ' + JSON.stringify({

1680
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -67,10 +67,20 @@
"x2js": "^3.4.4"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^28.0.0",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.3.0",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^12.1.0",
"eslint": "^8.57.0",
"eslint-plugin-compat": "^4.2.0",
"rollup": "^4.24.0",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-polyfill-node": "^0.13.0",
"stylelint": "^16.9.0",
"stylelint-config-standard-less": "^3.0.1"
"stylelint-config-standard-less": "^3.0.1",
"tslib": "^2.7.0",
"typescript": "^5.6.2"
},
"overrides": {
"minimist": "~1.2.3",
@ -97,7 +107,8 @@
"evict-inactive": "node scripts/evict-inactive.js",
"build": "node scripts/build.js",
"clear": "node scripts/clear.js",
"installtoken": "node scripts/install.js"
"installtoken": "node scripts/install.js",
"api": "rollup -c"
},
"browserslist": [
"> 0.5%, last 2 versions, Firefox ESR, not dead, not op_mini all"

39
rollup.config.mjs Normal file
View File

@ -0,0 +1,39 @@
import {nodeResolve} from "@rollup/plugin-node-resolve"
import commonjs from '@rollup/plugin-commonjs';
import builtins from 'rollup-plugin-node-builtins';
import typescript from '@rollup/plugin-typescript';
import terser from '@rollup/plugin-terser';
import json from '@rollup/plugin-json';
//import nodePolyfills from 'rollup-plugin-polyfill-node';
export default {
//input: "./_src/worker/index.ts",
input: "./_src/worker/store.ts",
output: {
name: 'cryptpad-worker',
file: "./_build/worker.bundle.js",
format: "umd"
},
plugins: [
json(),
typescript(),
builtins(),
nodeResolve({
}),
commonjs({
ignore:['crypto'] // required by tweetnacl for node
}),
terser({
format: {
comments: 'some',
beautify: true,
ecma: '2015',
},
compress: false,
mangle: false,
module: true,
}),
//nodePolyfills( /* options */ )
]
}

32
testapi.js Normal file
View File

@ -0,0 +1,32 @@
const Messages = require('./_src/messages');
const AppConfig = require('./customize/application_config');
const App = require('./_build/worker.bundle');
const Http = require('node:http');
let start = ApiConfig => {
App.start(ApiConfig, AppConfig, Keys);
};
let getApi = (file, cb) => {
Http.get(`http://localhost:3000/api/${file}`, res => {
let body = '';
res.on('data', data => { body += data; });
res.on('end', () => {
try {
cb(JSON.parse(body.slice(27,-5)));
} catch (e) {
console.error(e);
}
});
});
};
getApi('config', ApiConfig => {
getApi('broadcast', Broadcast => {
App.start({
ApiConfig, Broadcast, AppConfig, Messages
});
});
});

11
tsconfig.json Normal file
View File

@ -0,0 +1,11 @@
{
"compilerOptions": {
"module": "esnext",
"target": "es6",
"lib": ["ES2017", "DOM", "ES2020"],
"moduleResolution": "node",
"outDir": "./_build"
},
"include": ["_src/**/*"]
}

View File

@ -7,7 +7,8 @@
* If you want to change some configurable values, use the '/customize/application_config.js'
* file (make a copy from /customize.dist/application_config.js)
*/
define(function() {
(() => {
const factory = () => {
var AppConfig = {};
/* Select the buttons displayed on the main page to create new collaborative sessions.
@ -300,4 +301,13 @@ define(function() {
AppConfig.emojiAvatars = '🐵 🐒 🐶 🐩 🐺 🐱 🐯 🐴 🐎 🐮 🐷 🐗 🐑 🐫 🐘 🐭 🐹 🐰 🐻 🐨 🐼 🐔 🐣 🐥 🐢 🐍 🐲 🐳 🐬 🐟 🐠 🐡 🐙 🐚 🐌 🐛 🐝 🐞 💐 🌸 💮 🌹 🌺 🌻 🌼 🌷 🌱 🌴 🌵 🌾 🌿 🍀 🍁 🍂 🍃 🍄 💫 🌛 ⛄ 🔥 💧 🌊 🎃 👹 👺 👻 👽 👾'.split(/\s+/);
return AppConfig;
});
};
if (typeof(module) !== 'undefined' && module.exports) {
module.exports = factory();
} else if ((typeof(define) !== 'undefined' && define !== null) && (define.amd !== null)) {
define([], factory);
} else {
// unsupported initialization
}
})();

View File

@ -18,12 +18,15 @@ define([
'/common/outer/login-block.js',
'/common/common-credential.js',
'/customize/login.js',
'/common/worker.bundle.js',
'/customize/application_config.js',
'/components/nthen/index.js',
], function (Config, Messages, Util, Hash, Cache,
Messaging, Constants, Feedback, Visible, UserObject, LocalStore, Channel, Block,
Cred, Login, AppConfig, Nthen) {
Cred, Login, Worker, AppConfig, Nthen) {
console.error(Worker);
/* This file exposes functionality which is specific to Cryptpad, but not to
any particular pad type. This includes functions for committing metadata
@ -2620,7 +2623,9 @@ define([
driveEvents: !rdyCfg.noDrive, //rdyCfg.driveEvents // Boolean
lastVisit: Number(localStorage.lastVisit) || undefined,
blockId: blockId,
blockHash: blockHash
blockHash: blockHash,
Messages,
AppConfig
};
common.userHash = userHash || LocalStore.getUserHash();

View File

@ -3,33 +3,33 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
define([
'/api/config',
'/api/config', // From outside
'json.sortify',
'/common/userObject.js',
'/common/proxy-manager.js',
'/common/migrate-user-object.js',
'/common/common-hash.js',
'/common/common-util.js',
'/common/common-constants.js',
'/common/common-feedback.js',
'/common/common-realtime.js',
'/common/common-messaging.js',
'/common/pinpad.js',
'/common/outer/cache-store.js',
'/common/outer/sharedfolder.js',
'/common/userObject.js', // OK
'/common/proxy-manager.js', // OK
'/common/migrate-user-object.js', // OK
'/common/common-hash.js', // OK
'/common/common-util.js', // OK
'/common/common-constants.js', // OK
'/common/common-feedback.js', // OK
'/common/common-realtime.js', // OK
'/common/common-messaging.js', // OK
'/common/pinpad.js', // OK
'/common/outer/cache-store.js', // OK
'/common/outer/sharedfolder.js', // OK
'/common/outer/cursor.js',
'/common/outer/support.js',
'/common/outer/integration.js',
'/common/outer/onlyoffice.js',
'/common/outer/mailbox.js',
'/common/outer/mailbox.js', // OK
'/common/outer/profile.js',
'/common/outer/team.js',
'/common/outer/messenger.js',
'/common/outer/history.js',
'/common/outer/calendar.js',
'/common/outer/login-block.js',
'/common/outer/network-config.js',
'/customize/application_config.js',
'/common/outer/login-block.js', // OK
'/common/outer/network-config.js', // OK
'/customize/application_config.js', // OK
'/components/chainpad-crypto/crypto.js',
'/components/chainpad/chainpad.dist.js',
@ -131,7 +131,7 @@ define([
obj[key] = data.value;
}
if (!data.teamId) {
broadcast([clientId], "UPDATE_METADATA");
broadcast([clientId], "UPDATE_METADATA");
if (Array.isArray(path) && path[0] === 'profile' && store.messenger) {
Messaging.updateMyData(store);
}
@ -2945,6 +2945,7 @@ define([
var connect = function (clientId, data, cb) {
var hash = data.userHash || data.anonHash || Hash.createRandomHash('drive');
if (!hash) {
return void cb({error: '[Store.init] Unable to find or create a drive hash. Aborting...'});
}

View File

@ -2,16 +2,14 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later
define([
'/common/userObject.js',
'/common/common-util.js',
'/common/common-hash.js',
'/common/outer/sharedfolder.js',
'/customize/messages.js',
'/common/common-feedback.js',
'/components/nthen/index.js',
], function (UserObject, Util, Hash, SF, Messages, Feedback, nThen) {
(() => {
const factory = (UserObject, Util, Hash,
SF, Messages = {}, Feedback, nThen) => {
let setCustomize = data => {
Messages = data.Messages;
UO.setCustomize(data);
};
var getConfig = function (Env) {
var cfg = {};
@ -1375,6 +1373,7 @@ define([
},
folders: {}
};
uoConfig.removeProxy = function (id) {
removeProxy(Env, id);
};
@ -1780,7 +1779,35 @@ define([
};
return {
setCustomize,
create: create,
createInner: createInner
};
});
};
if (typeof(module) !== 'undefined' && module.exports) {
// We don't need Messages in worker or node
module.exports = factory(
require('./userObject'),
require('./common-util'),
require('./common-hash'),
require('../worker/modules/sharedfolder'),
undefined,
require('./common-feedback'),
require('nthen')
);
} else if ((typeof(define) !== 'undefined' && define !== null) && (define.amd !== null)) {
define([
'/common/userObject.js',
'/common/common-util.js',
'/common/common-hash.js',
'/common/outer/sharedfolder.js',
'/customize/messages.js',
'/common/common-feedback.js',
'/components/nthen/index.js',
], factory);
} else {
// unsupported initialization
}
})();

View File

@ -2,17 +2,17 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later
define([
'/customize/application_config.js',
'/common/common-util.js',
'/common/common-hash.js',
'/common/common-constants.js',
'/common/outer/userObject.js',
'/customize/messages.js',
'/components/chainpad-crypto/crypto.js',
], function (AppConfig, Util, Hash, Constants, OuterFO, Messages, Crypto) {
(() => {
const factory = (AppConfig = {}, Util, Hash,
Constants, UOSetter, Crypto, Messages = {}) => {
var module = {};
module.setCustomize = (data) => {
Messages = data.Messages;
AppConfig = data.AppConfig;
UOSetter.setCustomize(data);
};
var ROOT = module.ROOT = "root";
var UNSORTED = module.UNSORTED = "unsorted";
var TRASH = module.TRASH = "trash";
@ -163,7 +163,7 @@ define([
var logError = config.logError || logging;
var debug = exp.debug = config.debug || logging;
exp.fixFiles = function () {}; // Overriden by OuterFO
exp.fixFiles = function () {}; // Overriden by UOSetter
var error = exp.error = function() {
if (sframeChan) {
@ -180,7 +180,7 @@ define([
if (config.outer) {
// Extend "exp" with methods used only outside of the iframe (requires access to store)
OuterFO.init(config, exp, files);
UOSetter.init(config, exp, files);
}
@ -967,4 +967,30 @@ define([
return exp;
};
return module;
});
};
if (typeof(module) !== 'undefined' && module.exports) {
module.exports = factory(
undefined,
require('./common-util'),
require('./common-hash'),
require('./common-constants'),
require('./userObjectSetter'),
require('chainpad-crypto'),
undefined
);
} else if ((typeof(define) !== 'undefined' && define !== null) && (define.amd !== null)) {
define([
'/customize/application_config.js',
'/common/common-util.js',
'/common/common-hash.js',
'/common/common-constants.js',
'/common/userObjectSetter.js',
'/components/chainpad-crypto/crypto.js',
'/customize/messages.js',
], factory);
} else {
// unsupported initialization
}
})();

View File

@ -2,15 +2,17 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later
define([
'/customize/application_config.js',
'/common/common-util.js',
'/common/common-hash.js',
'/common/common-realtime.js',
'/customize/messages.js'
], function (AppConfig, Util, Hash, Realtime, Messages) {
(() => {
const factory = (AppConfig = {}, Util, Hash,
Realtime, Messages = {}) => {
var module = {};
module.setCustomize = (data) => {
Messages = data.Messages;
AppConfig = data.AppConfig;
UOSetter.setCustomize(data);
};
var clone = function (o) {
try { return JSON.parse(JSON.stringify(o)); }
catch (e) { return undefined; }
@ -22,6 +24,7 @@ define([
var readOnly = config.readOnly;
var Messages = config.Messages || {};
var ROOT = exp.ROOT;
var FILES_DATA = exp.FILES_DATA;
var STATIC_DATA = exp.STATIC_DATA;
@ -978,4 +981,26 @@ define([
};
return module;
});
};
if (typeof(module) !== 'undefined' && module.exports) {
module.exports = factory(
undefined,
require('./common-util'),
require('./common-hash'),
require('./common-realtime'),
undefined
);
} else if ((typeof(define) !== 'undefined' && define !== null) && (define.amd !== null)) {
define([
'/customize/application_config.js',
'/common/common-util.js',
'/common/common-hash.js',
'/common/common-realtime.js',
'/customize/messages.js',
], factory);
} else {
// unsupported initialization
}
})();