commandkit 0.1.7-dev.20231212163946 → 0.1.7

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/bin/build.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  // @ts-check
2
2
 
3
- import { readFile, writeFile } from 'node:fs/promises';
3
+ import { appendFile } from 'node:fs/promises';
4
4
  import { join } from 'node:path';
5
5
  import { build } from 'tsup';
6
6
  import { Colors, erase, findCommandKitConfig, panic, write } from './common.mjs';
@@ -14,7 +14,6 @@ export async function bootstrapProductionBuild(config) {
14
14
  antiCrash = true,
15
15
  src,
16
16
  main,
17
- requirePolyfill: polyfillRequire,
18
17
  } = await findCommandKitConfig(config);
19
18
 
20
19
  const status = ora('Creating optimized production build...\n').start();
@@ -40,7 +39,7 @@ export async function bootstrapProductionBuild(config) {
40
39
  entry: [src, '!dist', '!.commandkit', `!${outDir}`],
41
40
  });
42
41
 
43
- await injectShims(outDir, main, antiCrash, polyfillRequire);
42
+ await injectShims(outDir, main, antiCrash);
44
43
 
45
44
  status.succeed(
46
45
  Colors.green(`Build completed in ${(performance.now() - start).toFixed(2)}ms!`),
@@ -56,33 +55,14 @@ export async function bootstrapProductionBuild(config) {
56
55
  }
57
56
  }
58
57
 
59
- export async function injectShims(outDir, main, antiCrash, polyfillRequire) {
58
+ async function injectShims(outDir, main, antiCrash) {
60
59
  const path = join(process.cwd(), outDir, main);
61
60
 
62
- const head = ['\n\n;await (async()=>{', " 'use strict';"].join('\n');
63
- const tail = '\n})();';
64
- const requireScript = polyfillRequire
65
- ? [
66
- '// --- CommandKit require() polyfill ---',
67
- ' if (typeof require === "undefined") {',
68
- ' const { createRequire } = await import("node:module");',
69
- ' const __require = createRequire(import.meta.url);',
70
- ' Object.defineProperty(globalThis, "require", {',
71
- ' value: (id) => {',
72
- ' return __require(id);',
73
- ' },',
74
- ' configurable: true,',
75
- ' enumerable: false,',
76
- ' writable: true,',
77
- ' });',
78
- ' }',
79
- '// --- CommandKit require() polyfill ---',
80
- ].join('\n')
81
- : '';
82
-
83
61
  const antiCrashScript = antiCrash
84
62
  ? [
85
- '// --- CommandKit Anti-Crash Monitor ---',
63
+ '\n\n// --- CommandKit Anti-Crash Monitor ---',
64
+ ';(()=>{',
65
+ " 'use strict';",
86
66
  " // 'uncaughtException' event is supposed to be used to perform synchronous cleanup before shutting down the process",
87
67
  ' // instead of using it as a means to resume operation.',
88
68
  ' // But it exists here due to compatibility reasons with discord bot ecosystem.',
@@ -95,12 +75,12 @@ export async function injectShims(outDir, main, antiCrash, polyfillRequire) {
95
75
  ' process.on(e2, (r) => {',
96
76
  ' l(p(`${b} Unhandled promise rejection`)); l(p(`${b} ${r.stack || r}`));',
97
77
  ' });',
98
- '// --- CommandKit Anti-Crash Monitor ---',
78
+ '})();',
79
+ '// --- CommandKit Anti-Crash Monitor ---\n',
99
80
  ].join('\n')
100
81
  : '';
101
82
 
102
- const contents = await readFile(path, 'utf-8');
103
- const finalScript = [head, requireScript, antiCrashScript, tail, '\n\n', contents].join('\n');
83
+ const finalScript = [antiCrashScript].join('\n');
104
84
 
105
- return writeFile(path, finalScript);
85
+ return appendFile(path, finalScript);
106
86
  }
@@ -6,7 +6,6 @@ import { Colors, erase, findCommandKitConfig, panic, write } from './common.mjs'
6
6
  import { parseEnv } from './parse-env.mjs';
7
7
  import child_process from 'node:child_process';
8
8
  import ora from 'ora';
9
- import { injectShims } from './build.mjs';
10
9
 
11
10
  const RESTARTING_MSG_PATTERN = /^Restarting '|".+'|"\n?$/;
12
11
  const FAILED_RUNNING_PATTERN = /^Failed running '.+'|"\n?$/;
@@ -20,7 +19,6 @@ export async function bootstrapDevelopmentServer(opts) {
20
19
  envExtra = true,
21
20
  clearRestartLogs = true,
22
21
  outDir,
23
- requirePolyfill,
24
22
  } = await findCommandKitConfig(opts.config);
25
23
 
26
24
  if (!src) {
@@ -63,8 +61,6 @@ export async function bootstrapDevelopmentServer(opts) {
63
61
  watch: watchMode,
64
62
  });
65
63
 
66
- await injectShims('.commandkit', main, false, requirePolyfill);
67
-
68
64
  status.succeed(
69
65
  Colors.green(`Dev server started in ${(performance.now() - start).toFixed(2)}ms!\n`),
70
66
  );
package/dist/index.d.mts CHANGED
@@ -344,10 +344,6 @@ interface CommandKitConfig {
344
344
  * Whether or not to include anti-crash handler in production. Defaults to `true`.
345
345
  */
346
346
  antiCrash: boolean;
347
- /**
348
- * Whether or not to polyfill `require` function. Defaults to `true`.
349
- */
350
- requirePolyfill: boolean;
351
347
  }
352
348
  declare function getConfig(): CommandKitConfig;
353
349
  declare const requiredProps: readonly ["src", "main"];
package/dist/index.d.ts CHANGED
@@ -344,10 +344,6 @@ interface CommandKitConfig {
344
344
  * Whether or not to include anti-crash handler in production. Defaults to `true`.
345
345
  */
346
346
  antiCrash: boolean;
347
- /**
348
- * Whether or not to polyfill `require` function. Defaults to `true`.
349
- */
350
- requirePolyfill: boolean;
351
347
  }
352
348
  declare function getConfig(): CommandKitConfig;
353
349
  declare const requiredProps: readonly ["src", "main"];
package/dist/index.js CHANGED
@@ -1013,8 +1013,7 @@ var globalConfig = {
1013
1013
  minify: false,
1014
1014
  sourcemap: false,
1015
1015
  nodeOptions: [],
1016
- antiCrash: true,
1017
- requirePolyfill: true
1016
+ antiCrash: true
1018
1017
  };
1019
1018
  function getConfig() {
1020
1019
  return globalConfig;
package/dist/index.mjs CHANGED
@@ -984,8 +984,7 @@ var globalConfig = {
984
984
  minify: false,
985
985
  sourcemap: false,
986
986
  nodeOptions: [],
987
- antiCrash: true,
988
- requirePolyfill: true
987
+ antiCrash: true
989
988
  };
990
989
  function getConfig() {
991
990
  return globalConfig;
package/package.json CHANGED
@@ -1,58 +1,58 @@
1
1
  {
2
- "name": "commandkit",
3
- "description": "Beginner friendly command & event handler for Discord.js",
4
- "version": "0.1.7-dev.20231212163946",
5
- "license": "MIT",
6
- "main": "./dist/index.js",
7
- "module": "./dist/index.mjs",
8
- "types": "./dist/index.d.ts",
9
- "bin": "./bin/index.mjs",
10
- "exports": {
11
- ".": {
12
- "require": "./dist/index.js",
13
- "import": "./dist/index.mjs",
14
- "types": "./dist/index.d.ts"
2
+ "name": "commandkit",
3
+ "description": "Beginner friendly command & event handler for Discord.js",
4
+ "version": "0.1.7",
5
+ "license": "MIT",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.mjs",
8
+ "types": "./dist/index.d.ts",
9
+ "bin": "./bin/index.mjs",
10
+ "exports": {
11
+ ".": {
12
+ "require": "./dist/index.js",
13
+ "import": "./dist/index.mjs",
14
+ "types": "./dist/index.d.ts"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "bin"
20
+ ],
21
+ "scripts": {
22
+ "lint": "tsc",
23
+ "dev": "tsup --watch",
24
+ "build": "tsup",
25
+ "deploy": "npm publish",
26
+ "deploy-dev": "npm publish --access public --tag dev",
27
+ "test": "cd ./tests && node ../bin/index.mjs dev",
28
+ "test:build": "cd ./tests && node ../bin/index.mjs build",
29
+ "test:prod": "cd ./tests && node ../bin/index.mjs start"
30
+ },
31
+ "repository": {
32
+ "url": "git+https://github.com/underctrl-io/commandkit.git"
33
+ },
34
+ "homepage": "https://commandkit.js.org",
35
+ "keywords": [
36
+ "discord.js",
37
+ "command handler",
38
+ "event handler"
39
+ ],
40
+ "dependencies": {
41
+ "commander": "^11.1.0",
42
+ "dotenv": "^16.3.1",
43
+ "ora": "^7.0.1",
44
+ "rfdc": "^1.3.0",
45
+ "rimraf": "^5.0.5",
46
+ "tsup": "^7.2.0"
47
+ },
48
+ "devDependencies": {
49
+ "@types/node": "^20.5.9",
50
+ "discord.js": "^14.13.0",
51
+ "tsconfig": "workspace:*",
52
+ "tsx": "^3.12.8",
53
+ "typescript": "^5.1.6"
54
+ },
55
+ "peerDependencies": {
56
+ "discord.js": "^14"
15
57
  }
16
- },
17
- "files": [
18
- "dist",
19
- "bin"
20
- ],
21
- "scripts": {
22
- "lint": "tsc",
23
- "dev": "tsup --watch",
24
- "build": "tsup",
25
- "deploy": "npm publish",
26
- "deploy-dev": "npm publish --access public --tag dev",
27
- "test": "cd ./tests && node ../bin/index.mjs dev",
28
- "test:build": "cd ./tests && node ../bin/index.mjs build",
29
- "test:prod": "cd ./tests && node ../bin/index.mjs start"
30
- },
31
- "repository": {
32
- "url": "git+https://github.com/underctrl-io/commandkit.git"
33
- },
34
- "homepage": "https://commandkit.js.org",
35
- "keywords": [
36
- "discord.js",
37
- "command handler",
38
- "event handler"
39
- ],
40
- "dependencies": {
41
- "commander": "^11.1.0",
42
- "dotenv": "^16.3.1",
43
- "ora": "^7.0.1",
44
- "rfdc": "^1.3.0",
45
- "rimraf": "^5.0.5",
46
- "tsup": "^7.2.0"
47
- },
48
- "devDependencies": {
49
- "@types/node": "^20.5.9",
50
- "discord.js": "^14.13.0",
51
- "tsconfig": "workspace:*",
52
- "tsx": "^3.12.8",
53
- "typescript": "^5.1.6"
54
- },
55
- "peerDependencies": {
56
- "discord.js": "^14"
57
- }
58
- }
58
+ }