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

core: convert to ES modules #14182

Merged
merged 120 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
6fef56a
wip
connorjclark May 4, 2022
9aa2837
convert build
connorjclark May 5, 2022
05cea03
fix
connorjclark May 5, 2022
c9c2bd3
update
connorjclark May 5, 2022
612a82d
try to add build tsconfig
connorjclark May 5, 2022
4c6187b
hmmm
connorjclark May 5, 2022
9562c85
lok ok sure
connorjclark May 5, 2022
b70a80d
Apply suggestions from code review
connorjclark May 5, 2022
2be7c4e
fi
connorjclark May 5, 2022
53996df
Merge branch 'esm-build' of github.com:GoogleChrome/lighthouse into e…
connorjclark May 5, 2022
3de2ae4
Merge branch 'esm-build' into esm-core
connorjclark May 5, 2022
0e75155
wip
connorjclark May 5, 2022
938ea73
fix
connorjclark May 6, 2022
bc4b2b9
fix
connorjclark May 6, 2022
0ae4fb6
Merge branch 'esm-build' into esm-core
connorjclark May 6, 2022
c564757
cli --version working now
connorjclark May 6, 2022
90fd855
wip
connorjclark May 6, 2022
dc75dae
wip
connorjclark May 6, 2022
4bacbab
tests
connorjclark May 6, 2022
c69ceea
update
connorjclark May 6, 2022
d1e198d
update
connorjclark May 6, 2022
6fc50f9
Merge remote-tracking branch 'origin/master' into esm-build
connorjclark May 6, 2022
c85f31c
Merge remote-tracking branch 'origin/master' into async-config
connorjclark May 6, 2022
b512c2c
Config.fromJson
connorjclark May 6, 2022
9a63b38
comment
connorjclark May 6, 2022
02d613b
Merge branch 'esm-build' into esm-core
connorjclark May 6, 2022
1526f1d
Merge remote-tracking branch 'origin/master' into esm-core
connorjclark May 6, 2022
c1be47b
tweak test
connorjclark May 6, 2022
13a5979
rename
connorjclark May 6, 2022
33691f4
merge WIP async config branch
connorjclark May 6, 2022
ba02835
index-test passing
connorjclark May 7, 2022
4ff57a4
config-helpers-test passing
connorjclark May 7, 2022
03aa307
wip
connorjclark May 11, 2022
299036c
more wip
connorjclark May 11, 2022
84fb948
ignore type error
connorjclark May 11, 2022
a412cf1
working
connorjclark May 12, 2022
4218bf5
fix audits tests
connorjclark May 12, 2022
041ca98
starting to get gather mock tests working again
connorjclark May 13, 2022
6f79e1c
gather-runner tests passing
connorjclark May 13, 2022
9239006
Merge remote-tracking branch 'origin/master' into esm-core
connorjclark May 13, 2022
9f3e02f
gather tests passing
connorjclark May 13, 2022
d37d630
lib tests passing
connorjclark May 13, 2022
e7b852b
couple more tests working
connorjclark May 13, 2022
16e1a6c
config test working
connorjclark May 13, 2022
f078014
config tests passing
connorjclark May 13, 2022
52028ae
fraggle rock tests passing
connorjclark May 13, 2022
6882427
runner-test passing
connorjclark May 13, 2022
64b4dc0
fix importMock
connorjclark May 13, 2022
bcf025d
build-all working
connorjclark May 13, 2022
178746e
rm json import
connorjclark May 13, 2022
7fed6fe
fixed a lot of problems with build-bundle
connorjclark May 13, 2022
5666c14
test-bundle passing
connorjclark May 13, 2022
de71576
Merge remote-tracking branch 'origin/master' into esm-core
connorjclark May 14, 2022
7e0eb2e
convert chromium-synchronization esm
connorjclark May 14, 2022
6a4e524
fix collect strings
connorjclark May 14, 2022
381ca39
run-jest.sh for dum v8 workaround
connorjclark May 16, 2022
1953e40
wip shared
connorjclark May 16, 2022
86dca8e
fix shared/ tests
connorjclark May 16, 2022
3d81264
changes
connorjclark May 16, 2022
3378404
Merge remote-tracking branch 'origin/master' into esm-core
connorjclark May 16, 2022
e59ca47
delete old code in build
connorjclark May 16, 2022
44c7a83
keep retrying
connorjclark May 16, 2022
7262cf8
fix inline js
connorjclark May 16, 2022
9249e61
convert download content shell script
connorjclark May 16, 2022
b841b28
fix dt entry
connorjclark May 16, 2022
7d8b361
temp: run ci
connorjclark May 16, 2022
1dd3968
mkdir -p
connorjclark May 16, 2022
c00c994
Merge remote-tracking branch 'origin/master' into esm-core
connorjclark May 16, 2022
23b4add
hmm
connorjclark May 16, 2022
ebb1ca3
more c8
connorjclark May 17, 2022
dcf65e3
segfault handler
connorjclark May 17, 2022
9c9321f
hmm
connorjclark May 17, 2022
baded1d
nvm
connorjclark May 17, 2022
21a57c3
try runInBand
connorjclark May 17, 2022
b3c0579
tmp
connorjclark May 23, 2022
d262e36
Merge remote-tracking branch 'origin/master' into esm-core
connorjclark May 26, 2022
52d7e58
fix merge
connorjclark May 26, 2022
72af740
Merge remote-tracking branch 'origin/master' into esm-core
connorjclark Jun 17, 2022
7ba8fc1
Merge remote-tracking branch 'origin/master' into esm-core
connorjclark Jun 27, 2022
ce17c7d
wip: merge mocha and esm core branches
connorjclark Jun 29, 2022
e286fbb
maybe this
connorjclark Jun 29, 2022
60ff6ab
fix
connorjclark Jun 29, 2022
5c6579e
Merge remote-tracking branch 'origin/master' into esm-core-mocha
connorjclark Jun 29, 2022
ce71def
update
connorjclark Jun 29, 2022
20268fd
rm
connorjclark Jun 29, 2022
94c8347
fix build
connorjclark Jun 30, 2022
dfc5f52
fix root.js read json
connorjclark Jun 30, 2022
03baee4
update
connorjclark Jun 30, 2022
b1f6120
Merge remote-tracking branch 'origin/master' into esm-core-mocha
connorjclark Jun 30, 2022
b19d4a0
Merge remote-tracking branch 'origin/master' into esm-core-mocha
connorjclark Jun 30, 2022
67db107
fix coverage maybe
connorjclark Jun 30, 2022
c14a91d
disable pubads smoke, fix smokehouse bundle build
connorjclark Jun 30, 2022
60f534d
fix test-clients
connorjclark Jun 30, 2022
1c9b941
fix test-docs, add exports field and index.cjs
connorjclark Jun 30, 2022
db0c19a
Merge remote-tracking branch 'origin/master' into esm-core-mocha
connorjclark Jun 30, 2022
1101595
Merge remote-tracking branch 'origin/master' into esm-core-mocha
connorjclark Jun 30, 2022
c5146c4
fix merge
connorjclark Jun 30, 2022
6edab30
rm tmp code
connorjclark Jun 30, 2022
bf8d816
fix bundled lh
connorjclark Jul 1, 2022
c0a4bdb
revert unneeded change
connorjclark Jul 1, 2022
8140ad0
undo change
connorjclark Jul 1, 2022
d1568ea
remove pkg.exports and update recipes
connorjclark Jul 1, 2022
b7fe3ee
util.cjs
connorjclark Jul 1, 2022
29a12bb
pr
connorjclark Jul 1, 2022
541a9c7
createTestTrace named export
connorjclark Jul 1, 2022
fe39155
nit
connorjclark Jul 1, 2022
5e21f87
rename
connorjclark Jul 2, 2022
69cdea5
Merge branch 'master' into esm-core-mocha
connorjclark Jul 7, 2022
fc5e402
i18n: fix collect-strings on windows with pathToFileURL
connorjclark Jul 8, 2022
6508c29
tweak
connorjclark Jul 8, 2022
994d8c2
Merge remote-tracking branch 'origin/master' into esm-core-mocha
connorjclark Jul 11, 2022
7707693
update
connorjclark Jul 11, 2022
32c35ea
pr
connorjclark Jul 11, 2022
a8b864f
Merge remote-tracking branch 'origin/master' into esm-core-mocha
connorjclark Jul 11, 2022
b717a44
tests passing
connorjclark Jul 13, 2022
50d0884
unskip
connorjclark Jul 13, 2022
afc5e65
await all the things
connorjclark Jul 13, 2022
7888d97
fail fast units
connorjclark Jul 13, 2022
b1f39d3
missed one
connorjclark Jul 13, 2022
42bd6ba
isolate bin-test
connorjclark Jul 13, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = {
}],
'no-floating-decimal': 2,
'max-len': [2, 100, {
ignorePattern: 'readJson\\(',
ignorePattern: 'readJson\\(|^import ',
ignoreComments: true,
ignoreUrls: true,
tabWidth: 2,
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
strategy:
matrix:
node: ['14', '16', '17']
fail-fast: false
runs-on: ubuntu-latest
name: node ${{ matrix.node }}
env:
Expand Down
70 changes: 44 additions & 26 deletions build/build-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ import {createRequire} from 'module';

import esMain from 'es-main';
import {rollup} from 'rollup';
// @ts-expect-error: plugin has no types.
import PubAdsPlugin from 'lighthouse-plugin-publisher-ads/plugin.js';
// TODO(esmodules): convert pubads to esm
// // @ts-expect-error: plugin has no types.
// import PubAdsPlugin from 'lighthouse-plugin-publisher-ads/plugin.js';

import * as rollupPlugins from './rollup-plugins.js';
import Runner from '../lighthouse-core/runner.js';
import {Runner} from '../lighthouse-core/runner.js';
import {LH_ROOT} from '../root.js';
import {readJson} from '../lighthouse-core/test/test-utils.js';

Expand All @@ -31,8 +32,8 @@ const COMMIT_HASH = execSync('git rev-parse HEAD').toString().trim();

// HACK: manually include the lighthouse-plugin-publisher-ads audits.
/** @type {Array<string>} */
// @ts-expect-error
const pubAdsAudits = PubAdsPlugin.audits.map(a => a.path);
// // @ts-expect-error
// const pubAdsAudits = PubAdsPlugin.audits.map(a => a.path);

/** @param {string} file */
const isDevtools = file =>
Expand Down Expand Up @@ -83,20 +84,24 @@ async function buildBundle(entryPath, distPath, opts = {minify: true}) {
];

// Include lighthouse-plugin-publisher-ads.
if (isDevtools(entryPath) || isLightrider(entryPath)) {
dynamicModulePaths.push('lighthouse-plugin-publisher-ads');
pubAdsAudits.forEach(pubAdAudit => {
dynamicModulePaths.push(pubAdAudit);
});
}
// if (isDevtools(entryPath) || isLightrider(entryPath)) {
// dynamicModulePaths.push('lighthouse-plugin-publisher-ads');
// pubAdsAudits.forEach(pubAdAudit => {
// dynamicModulePaths.push(pubAdAudit);
// });
// }

const bundledMapEntriesCode = dynamicModulePaths.map(modulePath => {
const pathNoExt = modulePath.replace('.js', '');
return `['${pathNoExt}', require('${modulePath}')]`;
return `['${pathNoExt}', import('${modulePath}')]`;
}).join(',\n');

/** @type {Record<string, string>} */
const shimsObj = {};
const shimsObj = {
[require.resolve('../lighthouse-core/gather/connections/cri.js')]:
'export const CriConnection = {}',
[require.resolve('../package.json')]: `export const version = '${pkg.version}';`,
};

const modulesToIgnore = [
'puppeteer-core',
Expand All @@ -106,7 +111,6 @@ async function buildBundle(entryPath, distPath, opts = {minify: true}) {
'@sentry/node',
'source-map',
'ws',
require.resolve('../lighthouse-core/gather/connections/cri.js'),
];

// Don't include the stringified report in DevTools - see devtools-report-assets.js
Expand All @@ -124,9 +128,6 @@ async function buildBundle(entryPath, distPath, opts = {minify: true}) {
shimsObj[modulePath] = 'export default {}';
}

shimsObj[require.resolve('../package.json')] =
`export const version = '${pkg.version}';`;

const bundle = await rollup({
input: entryPath,
context: 'globalThis',
Expand All @@ -135,8 +136,6 @@ async function buildBundle(entryPath, distPath, opts = {minify: true}) {
delimiters: ['', ''],
values: {
'/* BUILD_REPLACE_BUNDLED_MODULES */': `[\n${bundledMapEntriesCode},\n]`,
'__dirname': (id) => `'${path.relative(LH_ROOT, path.dirname(id))}'`,
'__filename': (id) => `'${path.relative(LH_ROOT, id)}'`,
// This package exports to default in a way that causes Rollup to get confused,
// resulting in MessageFormat being undefined.
'require(\'intl-messageformat\').default': 'require(\'intl-messageformat\')',
Expand All @@ -148,6 +147,14 @@ async function buildBundle(entryPath, distPath, opts = {minify: true}) {
// TODO: Use globalThis directly.
'global.isLightrider': 'globalThis.isLightrider',
'global.isDevtools': 'globalThis.isDevtools',
// For some reason, `shim` doesn't work to force this module to return false, so instead
// just replace usages of it with false.
'esMain(import.meta)': 'false',
'import esMain from \'es-main\'': '',
// By default Rollup converts `import.meta` to a big mess of `document.currentScript && ...`,
// and uses the output name as the url. Instead, do a simpler conversion and use the
// module path.
'import.meta': (id) => `{url: '${path.relative(LH_ROOT, id)}'}`,
},
}),
rollupPlugins.alias({
Expand All @@ -160,14 +167,23 @@ async function buildBundle(entryPath, distPath, opts = {minify: true}) {
...shimsObj,
// Allows for plugins to import lighthouse.
'lighthouse': `
import Audit from '${require.resolve('../lighthouse-core/audits/audit.js')}';
import {Audit} from '${require.resolve('../lighthouse-core/audits/audit.js')}';
export {Audit};
`,
// Most node 'url' polyfills don't include the WHATWG `URL` property, but
// that's all that's needed, so make a mini-polyfill.
// @see https://github.com/GoogleChrome/lighthouse/issues/5273
// TODO: remove when not needed for pubads (https://github.com/googleads/publisher-ads-lighthouse-plugin/pull/325)
'url': 'export const URL = globalThis.URL;',
'url': `
export const URL = globalThis.URL;
export const fileURLToPath = url => url;
export default {URL, fileURLToPath};
`,
'module': `
export const createRequire = () => {
return {
resolve() {
throw new Error('createRequire.resolve is not supported in bundled Lighthouse');
},
};
};
`,
}),
rollupPlugins.json(),
rollupPlugins.inlineFs({verbose: false}),
Expand Down Expand Up @@ -211,6 +227,8 @@ async function buildBundle(entryPath, distPath, opts = {minify: true}) {
banner,
format: 'iife',
sourcemap: DEBUG,
// Suppress code splitting.
inlineDynamicImports: true,
});
await bundle.close();
}
Expand All @@ -222,7 +240,7 @@ async function cli(argv) {
// Take paths relative to cwd and build.
const [entryPath, distPath] = argv.slice(2)
.map(filePath => path.resolve(process.cwd(), filePath));
await buildBundle(entryPath, distPath);
await buildBundle(entryPath, distPath, {minify: !process.env.DEBUG});
}

// Test if called from the CLI or as a module.
Expand Down
4 changes: 0 additions & 4 deletions build/build-lightrider-bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ async function buildStaticServerBundle() {
const bundle = await rollup({
input: 'lighthouse-cli/test/fixtures/static-server.js',
plugins: [
rollupPlugins.shim({
'es-main': 'export default function() { return false; }',
}),
rollupPlugins.commonjs(),
rollupPlugins.nodeResolve(),
],
external: ['mime-types', 'glob'],
Expand Down
9 changes: 9 additions & 0 deletions build/build-smokehouse-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ async function main() {
rollupPlugins.shim({
[smokehouseCliFilename]:
'export function runLighthouse() { throw new Error("not supported"); }',
'module': `
export const createRequire = () => {
return {
resolve() {
throw new Error('createRequire.resolve is not supported in bundled Lighthouse');
},
};
};
`,
}),
rollupPlugins.inlineFs({verbose: Boolean(process.env.DEBUG)}),
rollupPlugins.commonjs(),
Expand Down
2 changes: 1 addition & 1 deletion build/plugins/inline-fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ function collapseToStringLiteral(node, filepath) {
}

case 'Identifier': {
if (node.name === '__dirname') {
if (node.name === '__dirname' || node.name === 'moduleDir') {
return path.dirname(filepath);
} else if (node.name === '__filename') {
return filepath;
Expand Down
19 changes: 11 additions & 8 deletions clients/devtools/devtools-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

import {Buffer} from 'buffer';

import lighthouse from '../../lighthouse-core/index.js';
import lighthouse, {legacyNavigation} from '../../lighthouse-core/index.js';
import {navigation, startTimespan, snapshot} from '../../lighthouse-core/fraggle-rock/api.js';
import RawProtocol from '../../lighthouse-core/gather/connections/raw.js';
import {RawConnection} from '../../lighthouse-core/gather/connections/raw.js';
import log from 'lighthouse-logger';
import {lookupLocale} from '../../lighthouse-core/lib/i18n/i18n.js';
import {registerLocaleData, getCanonicalLocales} from '../../shared/localization/format.js';
import constants from '../../lighthouse-core/config/constants.js';
import * as constants from '../../lighthouse-core/config/constants.js';

/** @typedef {import('../../lighthouse-core/gather/connections/connection.js')} Connection */

Expand Down Expand Up @@ -52,17 +52,18 @@ function createConfig(categoryIDs, device) {

return {
extends: 'lighthouse:default',
plugins: ['lighthouse-plugin-publisher-ads'],
// TODO(esmodules): re-enable when pubads works again
// plugins: ['lighthouse-plugin-publisher-ads'],
settings,
};
}

/**
* @param {RawProtocol.Port} port
* @return {RawProtocol}
* @param {import('../../lighthouse-core/gather/connections/raw.js').Port} port
* @return {RawConnection}
*/
function setUpWorkerConnection(port) {
return new RawProtocol(port);
return new RawConnection(port);
}

/** @param {(status: [string, string, string]) => void} listenCallback */
Expand Down Expand Up @@ -90,7 +91,7 @@ if (typeof self !== 'undefined') {
// @ts-expect-error
self.setUpWorkerConnection = setUpWorkerConnection;
// @ts-expect-error
self.runLighthouse = lighthouse.legacyNavigation;
self.runLighthouse = legacyNavigation;
// @ts-expect-error
self.runLighthouseNavigation = navigation;
// @ts-expect-error
Expand All @@ -110,4 +111,6 @@ if (typeof self !== 'undefined') {
// For the bundle smoke test.
// @ts-expect-error
global.runBundledLighthouse = lighthouse;
// @ts-expect-error
global.runBundledLighthouseLegacyNavigation = legacyNavigation;
}
16 changes: 8 additions & 8 deletions clients/lightrider/lightrider-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
/* global globalThis */

import {Buffer} from 'buffer';

import log from 'lighthouse-logger';
import lighthouse from '../../lighthouse-core/index.js';
import LighthouseError from '../../lighthouse-core/lib/lh-error.js';
import preprocessor from '../../lighthouse-core/lib/proto-preprocessor.js';
import assetSaver from '../../lighthouse-core/lib/asset-saver.js';

import {legacyNavigation} from '../../lighthouse-core/index.js';
import {LighthouseError} from '../../lighthouse-core/lib/lh-error.js';
import {processForProto} from '../../lighthouse-core/lib/proto-preprocessor.js';
import * as assetSaver from '../../lighthouse-core/lib/asset-saver.js';

import mobileConfig from '../../lighthouse-core/config/lr-mobile-config.js';
import desktopConfig from '../../lighthouse-core/config/lr-desktop-config.js';
Expand All @@ -24,7 +24,7 @@ const LR_PRESETS = {
desktop: desktopConfig,
};

/** @typedef {import('../../lighthouse-core/gather/connections/connection.js')} Connection */
/** @typedef {import('../../lighthouse-core/gather/connections/connection.js').Connection} Connection */

// Rollup seems to overlook some references to `Buffer`, so it must be made explicit.
// (`parseSourceMapFromDataUrl` breaks without this)
Expand Down Expand Up @@ -64,11 +64,11 @@ export async function runLighthouseInLR(connection, url, flags, lrOpts) {
}

try {
const runnerResult = await lighthouse.legacyNavigation(url, flags, config, connection);
const runnerResult = await legacyNavigation(url, flags, config, connection);
if (!runnerResult) throw new Error('Lighthouse finished without a runnerResult');

// pre process the LHR for proto
const preprocessedLhr = preprocessor.processForProto(runnerResult.lhr);
const preprocessedLhr = processForProto(runnerResult.lhr);

// When LR is called with |internal: {keep_raw_response: true, save_lighthouse_assets: true}|,
// we log artifacts to raw_response.artifacts.
Expand Down
4 changes: 2 additions & 2 deletions clients/test/lightrider/lightrider-entry-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import jestMock from 'jest-mock';
import {strict as assert} from 'assert';
import {runLighthouseInLR} from '../../lightrider/lightrider-entry.js';
import Runner from '../../../lighthouse-core/runner.js';
import LighthouseError from '../../../lighthouse-core/lib/lh-error.js';
import {Runner} from '../../../lighthouse-core/runner.js';
import {LighthouseError} from '../../../lighthouse-core/lib/lh-error.js';

describe('lightrider-entry', () => {
describe('#runLighthouseInLR', () => {
Expand Down
17 changes: 9 additions & 8 deletions docs/recipes/auth/example-lh-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
* See docs/recipes/auth/README.md for more.
*/

const puppeteer = require('puppeteer');
const lighthouse = require('lighthouse');
import puppeteer from 'puppeteer';
import lighthouse from 'lighthouse';
import esMain from 'es-main';

// This port will be used by Lighthouse later. The specific port is arbitrary.
const PORT = 8041;
Expand Down Expand Up @@ -71,11 +72,11 @@ async function main() {
console.log(JSON.stringify(result.lhr, null, 2));
}

if (require.main === module) {
if (esMain(import.meta)) {
main();
} else {
module.exports = {
login,
logout,
};
}

export {
login,
logout,
};
2 changes: 2 additions & 0 deletions docs/recipes/auth/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"private": true,
"type": "module",
"scripts": {
"start": "node server/server.js"
},
"dependencies": {
"es-main": "^1.2.0",
"express": "^4.17.1",
"express-session": "^1.16.2",
"lighthouse": "file:../../../dist/lighthouse.tgz",
Expand Down
26 changes: 16 additions & 10 deletions docs/recipes/auth/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@
* page. See docs/recipes/auth/README.md for more.
*/

const createError = require('http-errors');
const express = require('express');
const morgan = require('morgan');
const session = require('express-session');
const http = require('http');
const path = require('path');
const PUBLIC_DIR = path.join(__dirname, 'public');
import createError from 'http-errors';

import express from 'express';
import morgan from 'morgan';
import session from 'express-session';
import http from 'http';
import path from 'path';
import url from 'url';
import esMain from 'es-main';

const moduleDir = path.dirname(url.fileURLToPath(import.meta.url));
const PUBLIC_DIR = path.join(moduleDir, 'public');

const app = express();

Expand Down Expand Up @@ -78,8 +83,9 @@ app.use(function(err, req, res, next) {
});

const server = http.createServer(app);
if (require.main === module) {

if (esMain(import.meta)) {
server.listen(10632);
} else {
module.exports = server;
}

export default server;
Loading