arri 0.63.2 → 0.63.3

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/dist/index.cjs CHANGED
@@ -8,8 +8,9 @@ const codegenTs = require('@arrirpc/codegen-ts');
8
8
  const common = require('./shared/arri.27334236.cjs');
9
9
  const node_child_process = require('node:child_process');
10
10
  const fs = require('node:fs');
11
- const fs$1 = require('node:fs/promises');
12
11
  const path = require('node:path');
12
+ const chokidar = require('chokidar');
13
+ const fs$1 = require('node:fs/promises');
13
14
  const codegenUtils = require('@arrirpc/codegen-utils');
14
15
  const listhen = require('@joshmossas/listhen');
15
16
  const esbuild = require('esbuild');
@@ -37,11 +38,175 @@ function _interopNamespaceCompat(e) {
37
38
  return n;
38
39
  }
39
40
 
40
- const fs__namespace = /*#__PURE__*/_interopNamespaceCompat(fs$1);
41
+ const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
41
42
  const path__default = /*#__PURE__*/_interopDefaultCompat(path);
43
+ const chokidar__default = /*#__PURE__*/_interopDefaultCompat(chokidar);
44
+ const fs__namespace = /*#__PURE__*/_interopNamespaceCompat(fs$1);
42
45
  const esbuild__default = /*#__PURE__*/_interopDefaultCompat(esbuild);
43
46
  const prettier__default = /*#__PURE__*/_interopDefaultCompat(prettier);
44
47
 
48
+ function goServer(options = {}) {
49
+ const outDir = options.outputDir ?? ".output";
50
+ const resolvedOutDir = options.cwd ? path__default.resolve(options.cwd, outDir) : outDir;
51
+ return common.defineServerConfig({
52
+ devFn: async (_, generators) => {
53
+ if (!fs__default.existsSync(resolvedOutDir)) {
54
+ fs__default.mkdirSync(resolvedOutDir);
55
+ }
56
+ const ignoredDirs = ["node_modules", ".arri", ".output"];
57
+ const watcher = chokidar__default.watch(".", {
58
+ ignoreInitial: true,
59
+ ignored: (path2, stats) => {
60
+ if (stats?.isFile() == true && !path2.endsWith(".go")) {
61
+ return true;
62
+ }
63
+ if (stats?.isDirectory()) {
64
+ for (const dir of ignoredDirs) {
65
+ if (path2.includes(dir)) {
66
+ return true;
67
+ }
68
+ }
69
+ }
70
+ return false;
71
+ },
72
+ cwd: options.cwd
73
+ });
74
+ let childProcess;
75
+ async function spawnProcess() {
76
+ try {
77
+ node_child_process.execSync(`go build -o ${outDir}/server`, {
78
+ stdio: "inherit",
79
+ cwd: options.cwd
80
+ });
81
+ childProcess = node_child_process.spawn(
82
+ `${outDir}/server`,
83
+ [`--def-out=${outDir}/__definition.json`],
84
+ {
85
+ stdio: "inherit",
86
+ cwd: options.cwd
87
+ }
88
+ );
89
+ childProcess.on("error", (_2) => {
90
+ childProcess?.kill("SIGTERM");
91
+ childProcess?.removeAllListeners();
92
+ childProcess = void 0;
93
+ });
94
+ childProcess.on("close", (_2) => {
95
+ childProcess?.removeAllListeners();
96
+ childProcess = void 0;
97
+ });
98
+ } catch (err) {
99
+ common.logger.error(err);
100
+ }
101
+ }
102
+ async function closeChildProcess() {
103
+ if (!childProcess)
104
+ return true;
105
+ return new Promise((res, rej) => {
106
+ childProcess?.on("close", () => res(true));
107
+ childProcess?.on("exit", () => res(true));
108
+ childProcess?.on("error", (err) => {
109
+ rej(err);
110
+ });
111
+ childProcess?.kill("SIGTERM");
112
+ });
113
+ }
114
+ spawnProcess();
115
+ watcher.on("all", async (evt) => {
116
+ common.logger.info(`Changed detected. Restarting server...`);
117
+ switch (evt) {
118
+ case "addDir":
119
+ return;
120
+ default: {
121
+ await closeChildProcess();
122
+ childProcess?.removeAllListeners();
123
+ childProcess = void 0;
124
+ spawnProcess();
125
+ }
126
+ }
127
+ });
128
+ if (generators.length == 0) {
129
+ common.logger.warn(
130
+ "No generators specified in arri config. Skipping codegen."
131
+ );
132
+ return;
133
+ }
134
+ let defFileCache = "";
135
+ let hasRunGenerators = false;
136
+ async function handleAppDef() {
137
+ let defFile = "";
138
+ try {
139
+ defFile = fs__default.readFileSync(
140
+ `${resolvedOutDir}/__definition.json`,
141
+ "utf8"
142
+ );
143
+ } catch (_2) {
144
+ return;
145
+ }
146
+ if (!defFile || defFile == defFileCache) {
147
+ return;
148
+ }
149
+ const startTime = /* @__PURE__ */ new Date();
150
+ if (hasRunGenerators) {
151
+ common.logger.info(
152
+ "App definition updated. Rerunning generators..."
153
+ );
154
+ } else {
155
+ common.logger.info("Running generators...");
156
+ }
157
+ defFileCache = defFile;
158
+ const appDef = JSON.parse(defFile);
159
+ await Promise.allSettled(
160
+ generators.map((gen) => gen.generator(appDef, true))
161
+ );
162
+ common.logger.success(
163
+ `Ran ${generators.length} generator(s) in ${( new Date()).getTime() - startTime.getTime()}ms`
164
+ );
165
+ hasRunGenerators = true;
166
+ }
167
+ const appDefWatcher = chokidar__default.watch(
168
+ [`${outDir}/__definition.json`],
169
+ {
170
+ cwd: options.cwd
171
+ }
172
+ );
173
+ appDefWatcher.on("add", () => handleAppDef());
174
+ appDefWatcher.on("change", () => handleAppDef());
175
+ },
176
+ buildFn: async (_, generators) => {
177
+ if (!fs__default.existsSync(outDir)) {
178
+ fs__default.mkdirSync(outDir);
179
+ }
180
+ node_child_process.execSync(`go build -o ${outDir}/server`, {
181
+ stdio: "inherit"
182
+ });
183
+ node_child_process.execSync(
184
+ `${outDir}/server def -output ${outDir}/__definition.json`,
185
+ {
186
+ stdio: "inherit"
187
+ }
188
+ );
189
+ if (generators.length === 0) {
190
+ common.logger.warn(
191
+ "No generators specified in arri config. Skipping codegen."
192
+ );
193
+ return;
194
+ }
195
+ const startTime = /* @__PURE__ */ new Date();
196
+ common.logger.info(`Running generators...`);
197
+ const appDef = JSON.parse(
198
+ fs__default.readFileSync(`${resolvedOutDir}/__definition.json`, "utf8")
199
+ );
200
+ await Promise.all(
201
+ generators.map((gen) => gen.generator(appDef, false))
202
+ );
203
+ common.logger.success(
204
+ `Ran ${generators.length} generator(s) in ${( new Date()).getTime() - startTime.getTime()}ms`
205
+ );
206
+ }
207
+ });
208
+ }
209
+
45
210
  function tsServer(serverConfig) {
46
211
  return common.defineServerConfig({
47
212
  devArgs: void 0,
@@ -571,7 +736,8 @@ const getRpcMetaFromPath = (config, filePath) => {
571
736
  };
572
737
 
573
738
  const servers = {
574
- tsServer
739
+ tsServer,
740
+ goServer
575
741
  };
576
742
 
577
743
  const generators = {
package/dist/index.d.cts CHANGED
@@ -29,6 +29,12 @@ interface ArriConfig<TDevArgs extends ArgsDef | undefined = any, TBuildArgs exte
29
29
  declare function isArriConfig(input: unknown): input is ArriConfig;
30
30
  declare function defineConfig(config: ArriConfig): ArriConfig;
31
31
 
32
+ interface GoServerOptions {
33
+ outputDir?: string;
34
+ cwd?: string;
35
+ }
36
+ declare function goServer(options?: GoServerOptions): ServerConfig<any, any>;
37
+
32
38
  declare function tsServer(serverConfig?: TsServerConfig): ServerConfig<undefined, undefined>;
33
39
  interface TsServerConfig {
34
40
  port?: number;
@@ -64,6 +70,7 @@ interface TsServerConfig {
64
70
 
65
71
  declare const servers: {
66
72
  readonly tsServer: typeof tsServer;
73
+ readonly goServer: typeof goServer;
67
74
  };
68
75
 
69
76
  declare const generators: {
package/dist/index.d.mts CHANGED
@@ -29,6 +29,12 @@ interface ArriConfig<TDevArgs extends ArgsDef | undefined = any, TBuildArgs exte
29
29
  declare function isArriConfig(input: unknown): input is ArriConfig;
30
30
  declare function defineConfig(config: ArriConfig): ArriConfig;
31
31
 
32
+ interface GoServerOptions {
33
+ outputDir?: string;
34
+ cwd?: string;
35
+ }
36
+ declare function goServer(options?: GoServerOptions): ServerConfig<any, any>;
37
+
32
38
  declare function tsServer(serverConfig?: TsServerConfig): ServerConfig<undefined, undefined>;
33
39
  interface TsServerConfig {
34
40
  port?: number;
@@ -64,6 +70,7 @@ interface TsServerConfig {
64
70
 
65
71
  declare const servers: {
66
72
  readonly tsServer: typeof tsServer;
73
+ readonly goServer: typeof goServer;
67
74
  };
68
75
 
69
76
  declare const generators: {
package/dist/index.d.ts CHANGED
@@ -29,6 +29,12 @@ interface ArriConfig<TDevArgs extends ArgsDef | undefined = any, TBuildArgs exte
29
29
  declare function isArriConfig(input: unknown): input is ArriConfig;
30
30
  declare function defineConfig(config: ArriConfig): ArriConfig;
31
31
 
32
+ interface GoServerOptions {
33
+ outputDir?: string;
34
+ cwd?: string;
35
+ }
36
+ declare function goServer(options?: GoServerOptions): ServerConfig<any, any>;
37
+
32
38
  declare function tsServer(serverConfig?: TsServerConfig): ServerConfig<undefined, undefined>;
33
39
  interface TsServerConfig {
34
40
  port?: number;
@@ -64,6 +70,7 @@ interface TsServerConfig {
64
70
 
65
71
  declare const servers: {
66
72
  readonly tsServer: typeof tsServer;
73
+ readonly goServer: typeof goServer;
67
74
  };
68
75
 
69
76
  declare const generators: {
package/dist/index.mjs CHANGED
@@ -5,10 +5,11 @@ import { swiftClientGenerator } from '@arrirpc/codegen-swift';
5
5
  import { typescriptClientGenerator } from '@arrirpc/codegen-ts';
6
6
  import { d as defineServerConfig, l as logger, i as isInsideDir } from './shared/arri.cc4e1de8.mjs';
7
7
  export { D as DEV_DEFINITION_ENDPOINT, b as defineConfig, a as isArriConfig, c as isServerConfig } from './shared/arri.cc4e1de8.mjs';
8
- import { execSync } from 'node:child_process';
9
- import { existsSync, readFileSync } from 'node:fs';
10
- import * as fs from 'node:fs/promises';
8
+ import { execSync, spawn } from 'node:child_process';
9
+ import fs$1, { existsSync, readFileSync } from 'node:fs';
11
10
  import path from 'node:path';
11
+ import chokidar from 'chokidar';
12
+ import * as fs from 'node:fs/promises';
12
13
  import { isAppDefinition, camelCase, removeDisallowedChars, kebabCase } from '@arrirpc/codegen-utils';
13
14
  export { createAppDefinition } from '@arrirpc/codegen-utils';
14
15
  import { listen } from '@joshmossas/listhen';
@@ -23,6 +24,168 @@ import '@arrirpc/schema';
23
24
  import 'consola';
24
25
  import 'ofetch';
25
26
 
27
+ function goServer(options = {}) {
28
+ const outDir = options.outputDir ?? ".output";
29
+ const resolvedOutDir = options.cwd ? path.resolve(options.cwd, outDir) : outDir;
30
+ return defineServerConfig({
31
+ devFn: async (_, generators) => {
32
+ if (!fs$1.existsSync(resolvedOutDir)) {
33
+ fs$1.mkdirSync(resolvedOutDir);
34
+ }
35
+ const ignoredDirs = ["node_modules", ".arri", ".output"];
36
+ const watcher = chokidar.watch(".", {
37
+ ignoreInitial: true,
38
+ ignored: (path2, stats) => {
39
+ if (stats?.isFile() == true && !path2.endsWith(".go")) {
40
+ return true;
41
+ }
42
+ if (stats?.isDirectory()) {
43
+ for (const dir of ignoredDirs) {
44
+ if (path2.includes(dir)) {
45
+ return true;
46
+ }
47
+ }
48
+ }
49
+ return false;
50
+ },
51
+ cwd: options.cwd
52
+ });
53
+ let childProcess;
54
+ async function spawnProcess() {
55
+ try {
56
+ execSync(`go build -o ${outDir}/server`, {
57
+ stdio: "inherit",
58
+ cwd: options.cwd
59
+ });
60
+ childProcess = spawn(
61
+ `${outDir}/server`,
62
+ [`--def-out=${outDir}/__definition.json`],
63
+ {
64
+ stdio: "inherit",
65
+ cwd: options.cwd
66
+ }
67
+ );
68
+ childProcess.on("error", (_2) => {
69
+ childProcess?.kill("SIGTERM");
70
+ childProcess?.removeAllListeners();
71
+ childProcess = void 0;
72
+ });
73
+ childProcess.on("close", (_2) => {
74
+ childProcess?.removeAllListeners();
75
+ childProcess = void 0;
76
+ });
77
+ } catch (err) {
78
+ logger.error(err);
79
+ }
80
+ }
81
+ async function closeChildProcess() {
82
+ if (!childProcess)
83
+ return true;
84
+ return new Promise((res, rej) => {
85
+ childProcess?.on("close", () => res(true));
86
+ childProcess?.on("exit", () => res(true));
87
+ childProcess?.on("error", (err) => {
88
+ rej(err);
89
+ });
90
+ childProcess?.kill("SIGTERM");
91
+ });
92
+ }
93
+ spawnProcess();
94
+ watcher.on("all", async (evt) => {
95
+ logger.info(`Changed detected. Restarting server...`);
96
+ switch (evt) {
97
+ case "addDir":
98
+ return;
99
+ default: {
100
+ await closeChildProcess();
101
+ childProcess?.removeAllListeners();
102
+ childProcess = void 0;
103
+ spawnProcess();
104
+ }
105
+ }
106
+ });
107
+ if (generators.length == 0) {
108
+ logger.warn(
109
+ "No generators specified in arri config. Skipping codegen."
110
+ );
111
+ return;
112
+ }
113
+ let defFileCache = "";
114
+ let hasRunGenerators = false;
115
+ async function handleAppDef() {
116
+ let defFile = "";
117
+ try {
118
+ defFile = fs$1.readFileSync(
119
+ `${resolvedOutDir}/__definition.json`,
120
+ "utf8"
121
+ );
122
+ } catch (_2) {
123
+ return;
124
+ }
125
+ if (!defFile || defFile == defFileCache) {
126
+ return;
127
+ }
128
+ const startTime = /* @__PURE__ */ new Date();
129
+ if (hasRunGenerators) {
130
+ logger.info(
131
+ "App definition updated. Rerunning generators..."
132
+ );
133
+ } else {
134
+ logger.info("Running generators...");
135
+ }
136
+ defFileCache = defFile;
137
+ const appDef = JSON.parse(defFile);
138
+ await Promise.allSettled(
139
+ generators.map((gen) => gen.generator(appDef, true))
140
+ );
141
+ logger.success(
142
+ `Ran ${generators.length} generator(s) in ${( new Date()).getTime() - startTime.getTime()}ms`
143
+ );
144
+ hasRunGenerators = true;
145
+ }
146
+ const appDefWatcher = chokidar.watch(
147
+ [`${outDir}/__definition.json`],
148
+ {
149
+ cwd: options.cwd
150
+ }
151
+ );
152
+ appDefWatcher.on("add", () => handleAppDef());
153
+ appDefWatcher.on("change", () => handleAppDef());
154
+ },
155
+ buildFn: async (_, generators) => {
156
+ if (!fs$1.existsSync(outDir)) {
157
+ fs$1.mkdirSync(outDir);
158
+ }
159
+ execSync(`go build -o ${outDir}/server`, {
160
+ stdio: "inherit"
161
+ });
162
+ execSync(
163
+ `${outDir}/server def -output ${outDir}/__definition.json`,
164
+ {
165
+ stdio: "inherit"
166
+ }
167
+ );
168
+ if (generators.length === 0) {
169
+ logger.warn(
170
+ "No generators specified in arri config. Skipping codegen."
171
+ );
172
+ return;
173
+ }
174
+ const startTime = /* @__PURE__ */ new Date();
175
+ logger.info(`Running generators...`);
176
+ const appDef = JSON.parse(
177
+ fs$1.readFileSync(`${resolvedOutDir}/__definition.json`, "utf8")
178
+ );
179
+ await Promise.all(
180
+ generators.map((gen) => gen.generator(appDef, false))
181
+ );
182
+ logger.success(
183
+ `Ran ${generators.length} generator(s) in ${( new Date()).getTime() - startTime.getTime()}ms`
184
+ );
185
+ }
186
+ });
187
+ }
188
+
26
189
  function tsServer(serverConfig) {
27
190
  return defineServerConfig({
28
191
  devArgs: void 0,
@@ -552,7 +715,8 @@ const getRpcMetaFromPath = (config, filePath) => {
552
715
  };
553
716
 
554
717
  const servers = {
555
- tsServer
718
+ tsServer,
719
+ goServer
556
720
  };
557
721
 
558
722
  const generators = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arri",
3
- "version": "0.63.2",
3
+ "version": "0.63.3",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -39,13 +39,13 @@
39
39
  "h3": "^1.13.0",
40
40
  "pathe": "^1.1.2",
41
41
  "prettier": "^3.3.3",
42
- "@arrirpc/codegen-dart": "0.63.2",
43
- "@arrirpc/codegen-rust": "0.63.2",
44
- "@arrirpc/codegen-swift": "0.63.2",
45
- "@arrirpc/codegen-kotlin": "0.63.2",
46
- "@arrirpc/codegen-ts": "0.63.2",
47
- "@arrirpc/schema": "0.63.2",
48
- "@arrirpc/codegen-utils": "0.63.2"
42
+ "@arrirpc/codegen-dart": "0.63.3",
43
+ "@arrirpc/codegen-rust": "0.63.3",
44
+ "@arrirpc/codegen-kotlin": "0.63.3",
45
+ "@arrirpc/codegen-swift": "0.63.3",
46
+ "@arrirpc/codegen-ts": "0.63.3",
47
+ "@arrirpc/codegen-utils": "0.63.3",
48
+ "@arrirpc/schema": "0.63.3"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/degit": "^2.8.6"