mirror of
https://github.com/wekan/wekan.git
synced 2026-11-05 01:20:07 -05:00
Add Dev server nobuild to both build menus with shared URL and port options. Load checkout JavaScript and templates in memory using the installed Meteor toolchain; start its bundled MongoDB on the next port and wait for owned database shutdown. Run server, Node, import, E2E and all supported Chromium, Firefox and WebKit regressions sequentially, stopping on failure. Preserve CommonJS semantics, native fetch, dynamic import namespaces and client source access boundaries. Document verified results and the remaining Windows and intermittent Firefox limits. Thanks to xet7 !
64 lines
2.1 KiB
JavaScript
64 lines
2.1 KiB
JavaScript
'use strict';
|
|
|
|
const swc = require('@swc/core');
|
|
|
|
// Preserve import()'s module-namespace contract. SWC's CommonJS wildcard helper
|
|
// has no Module tag; JSON containing a literal "default" key then looks like a
|
|
// translation map instead of a namespace to the application's i18n loader.
|
|
const dynamicHelper = `
|
|
function __wekanSourceImport(request) {
|
|
return Promise.resolve().then(function () {
|
|
const value = require(request);
|
|
if (value && (value.__esModule || value[Symbol.toStringTag] === 'Module')) return value;
|
|
return Object.assign(Object.create(null), value, {default: value, [Symbol.toStringTag]: 'Module'});
|
|
});
|
|
}
|
|
`;
|
|
function transform(source, filename, sourceMaps = false) {
|
|
const ast = swc.parseSync(source, {
|
|
syntax: 'ecmascript',
|
|
jsx: true,
|
|
target: 'es2022'
|
|
});
|
|
const pending = [ast];
|
|
// CommonJS dependencies may deliberately use sloppy-mode semantics. Adding
|
|
// a directive changes their behavior; only ES modules are implicitly strict.
|
|
// An explicit source directive remains intact in either kind of module.
|
|
const isESModule = ast.body.some(node => /^(ImportDeclaration|Export)/.test(node.type));
|
|
let hasDynamic = false;
|
|
while (pending.length) {
|
|
const node = pending.pop();
|
|
if (!node || typeof node !== 'object') continue;
|
|
if (node.type === 'CallExpression' && node.callee.type === 'Import') {
|
|
node.callee = {
|
|
type: 'Identifier',
|
|
span: node.callee.span,
|
|
ctxt: 0,
|
|
value: '__wekanSourceImport',
|
|
optional: false
|
|
};
|
|
hasDynamic = true;
|
|
}
|
|
for (const value of Object.values(node)) {
|
|
if (Array.isArray(value)) pending.push(...value);else if (value && typeof value === 'object') pending.push(value);
|
|
}
|
|
}
|
|
const result = swc.transformSync(ast, {
|
|
filename,
|
|
jsc: {
|
|
target: 'es2022'
|
|
},
|
|
module: {
|
|
type: 'commonjs',
|
|
strictMode: isESModule
|
|
},
|
|
sourceMaps
|
|
});
|
|
// Keep SWC's strict-mode directive and source-map line positions intact.
|
|
// Function declarations are hoisted, so imports can call the helper below.
|
|
return result.code + (hasDynamic ? dynamicHelper : '');
|
|
}
|
|
module.exports = {
|
|
transform
|
|
};
|