@colyseus/monitor 0.16.2 → 0.16.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build.mjs CHANGED
@@ -2,6 +2,7 @@ import path from 'path';
2
2
  import glob from 'fast-glob';
3
3
  import { fileURLToPath } from 'url';
4
4
  import ts from "typescript";
5
+ import fs from "fs";
5
6
  import esbuild from "esbuild";
6
7
 
7
8
  // we need to change up how __dirname is used for ES6 purposes
@@ -71,14 +72,36 @@ async function main() {
71
72
  sourcemap: "external",
72
73
  platform: "node",
73
74
  outExtension: { '.js': '.mjs', },
74
- plugins: [{
75
- name: 'add-mjs',
76
- setup(build) {
77
- build.onResolve({ filter: /.*/ }, (args) => {
78
- if (args.importer) return { path: args.path.replace(/^\.(.*)\.js$/, '.$1.mjs'), external: true }
79
- })
75
+ plugins: [
76
+ {
77
+ name: 'add-mjs',
78
+ setup(build) {
79
+ build.onResolve({ filter: /.*/ }, (args) => {
80
+ if (args.importer) return { path: args.path.replace(/^\.(.*)\.js$/, '.$1.mjs'), external: true }
81
+ })
82
+ },
80
83
  },
81
- }]
84
+ {
85
+ //
86
+ // WORKAROUND FOR __dirname usage in ESM
87
+ // TODO: need to have a better appraoch for ESM + CJS builds...
88
+ //
89
+ name: 'dirname',
90
+ setup(build) {
91
+ build.onLoad({ filter: /.*/ }, ({ path: filePath }) => {
92
+ let contents = fs.readFileSync(filePath, "utf8");
93
+ const loader = path.extname(filePath).substring(1);
94
+ contents = contents.replace("__dirname", `path.dirname(fileURLToPath(import.meta.url))`)
95
+ console.log({loader, contents})
96
+ return {
97
+ contents,
98
+ loader,
99
+ };
100
+ });
101
+ }
102
+
103
+ }
104
+ ]
82
105
  });
83
106
 
84
107
  // emit .d.ts files
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colyseus/monitor",
3
- "version": "0.16.2",
3
+ "version": "0.16.4",
4
4
  "description": "Web Monitoring Panel for Colyseus",
5
5
  "input": "./src/index.ts",
6
6
  "main": "./build/index.js",
@@ -1,14 +1,11 @@
1
1
  import express from 'express';
2
2
  import path from 'path';
3
- import { fileURLToPath } from 'url';
3
+ import { fileURLToPath } from 'url'; // required for ESM support. (esbuild uses it)
4
4
 
5
5
  import { getAPI } from './api.js';
6
6
  import './ext/Room.js';
7
7
 
8
- // __dirname is not available in ESM
9
- // @ts-ignore
10
- const getDirname = () => (typeof __dirname !== 'undefined') ? __dirname : path.dirname(fileURLToPath(import.meta.url));
11
- const frontendDirectory = path.resolve(getDirname(), "..", "build", "static");
8
+ const frontendDirectory = path.resolve(__dirname, "..", "build", "static");
12
9
 
13
10
  export interface MonitorOptions {
14
11
  columns: Array<