@ciderjs/gasnuki 0.2.5 → 0.2.6

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/README.ja.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # gasnuki
2
2
 
3
- [![Test Coverage](https://img.shields.io/badge/test%20coverage-83.65%25-green)](https://github.com/luthpg/gasnuki)
3
+ [![Test Coverage](https://img.shields.io/badge/test%20coverage-77.03%25-yellowgreen)](https://github.com/luthpg/gasnuki)
4
4
  [![License](https://img.shields.io/badge/license-ISC-blue.svg)](LICENSE)
5
5
  [![npm version](https://img.shields.io/npm/v/@ciderjs/gasnuki.svg)](https://www.npmjs.com/package/@ciderjs/gasnuki)
6
6
  [![GitHub issues](https://img.shields.io/github/issues/luthpg/gasnuki.svg)](https://github.com/luthpg/gasnuki/issues)
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @ciderjs/gasnuki
2
2
 
3
- [![Test Coverage](https://img.shields.io/badge/test%20coverage-83.65%25-green)](https://github.com/luthpg/gasnuki)
3
+ [![Test Coverage](https://img.shields.io/badge/test%20coverage-77.03%25-yellowgreen)](https://github.com/luthpg/gasnuki)
4
4
  [![License](https://img.shields.io/badge/license-ISC-blue.svg)](LICENSE)
5
5
  [![npm version](https://img.shields.io/npm/v/@ciderjs/gasnuki.svg)](https://www.npmjs.com/package/@ciderjs/gasnuki)
6
6
  [![GitHub issues](https://img.shields.io/github/issues/luthpg/gasnuki.svg)](https://github.com/luthpg/gasnuki/issues)
package/dist/cli.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  const path = require('node:path');
5
5
  const commander = require('commander');
6
- const index = require('./shared/gasnuki.Ce9vzQ2b.cjs');
6
+ const index = require('./shared/gasnuki.DH8w-v3n.cjs');
7
7
  require('chokidar');
8
8
  require('consola');
9
9
  require('node:fs');
@@ -24,7 +24,7 @@ function _interopNamespaceCompat(e) {
24
24
 
25
25
  const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
26
26
 
27
- const version = "0.2.5";
27
+ const version = "0.2.6";
28
28
 
29
29
  const parseArgs = async (command) => {
30
30
  const cliOpts = command.opts();
package/dist/cli.mjs CHANGED
@@ -1,14 +1,14 @@
1
1
  #! /usr/bin/env node
2
2
  import * as path from 'node:path';
3
3
  import { Command } from 'commander';
4
- import { l as loadConfig, g as generateTypes } from './shared/gasnuki.DJCCMztm.mjs';
4
+ import { l as loadConfig, g as generateTypes } from './shared/gasnuki.DgQBiLxg.mjs';
5
5
  import 'chokidar';
6
6
  import 'consola';
7
7
  import 'node:fs';
8
8
  import 'ts-morph';
9
9
  import 'jiti';
10
10
 
11
- const version = "0.2.5";
11
+ const version = "0.2.6";
12
12
 
13
13
  const parseArgs = async (command) => {
14
14
  const cliOpts = command.opts();
package/dist/index.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  require('node:path');
4
4
  require('chokidar');
5
5
  require('consola');
6
- const index = require('./shared/gasnuki.Ce9vzQ2b.cjs');
6
+ const index = require('./shared/gasnuki.DH8w-v3n.cjs');
7
7
  require('node:fs');
8
8
  require('ts-morph');
9
9
  require('jiti');
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import 'node:path';
2
2
  import 'chokidar';
3
3
  import 'consola';
4
- export { d as defineConfig, g as generateTypes } from './shared/gasnuki.DJCCMztm.mjs';
4
+ export { d as defineConfig, g as generateTypes } from './shared/gasnuki.DgQBiLxg.mjs';
5
5
  import 'node:fs';
6
6
  import 'ts-morph';
7
7
  import 'jiti';
@@ -92,86 +92,147 @@ const generateAppsScriptTypes = async ({
92
92
  const sourceFiles = project.getSourceFiles();
93
93
  consola.consola.info(`Found ${sourceFiles.length} source file(s).`);
94
94
  const methodDefinitions = [];
95
- const localDeclarations = [];
96
- const localDeclarationNames = /* @__PURE__ */ new Set();
95
+ const exportedDeclarations = [];
96
+ const exportedDeclarationNames = /* @__PURE__ */ new Set();
97
+ const exportedFunctions = [];
97
98
  for (const sourceFile of sourceFiles) {
98
99
  for (const iface of sourceFile.getInterfaces()) {
99
- const name = iface.getName?.();
100
- if (name && !name.endsWith("_")) {
101
- localDeclarations.push(iface);
102
- localDeclarationNames.add(name);
100
+ if (iface.isExported() && !iface.getName()?.endsWith("_")) {
101
+ exportedDeclarations.push(iface);
102
+ exportedDeclarationNames.add(iface.getName());
103
103
  }
104
104
  }
105
105
  for (const typeAlias of sourceFile.getTypeAliases()) {
106
- const name = typeAlias.getName();
107
- if (name && !name.endsWith("_")) {
108
- localDeclarations.push(typeAlias);
109
- localDeclarationNames.add(name);
106
+ if (typeAlias.isExported() && !typeAlias.getName().endsWith("_")) {
107
+ exportedDeclarations.push(typeAlias);
108
+ exportedDeclarationNames.add(typeAlias.getName());
110
109
  }
111
110
  }
112
111
  for (const func of sourceFile.getFunctions()) {
113
112
  const name = func.getName();
114
- if (name && !func.isAmbient() && !name.endsWith("_") && !SIMPLE_TRIGGER_FUNCTION_NAMES.includes(name)) {
115
- localDeclarations.push(func);
116
- localDeclarationNames.add(name);
113
+ if (func.isExported() && name && !name.endsWith("_") && !SIMPLE_TRIGGER_FUNCTION_NAMES.includes(name)) {
114
+ exportedDeclarations.push(func);
115
+ exportedDeclarationNames.add(name);
117
116
  methodDefinitions.push(getInterfaceMethodDefinition_(name, func));
117
+ exportedFunctions.push(func);
118
118
  }
119
119
  }
120
120
  for (const varStmt of sourceFile.getVariableStatements()) {
121
- if (varStmt.isAmbient()) continue;
121
+ if (!varStmt.isExported()) continue;
122
122
  for (const varDecl of varStmt.getDeclarations()) {
123
123
  const name = varDecl.getName();
124
124
  const initializer = varDecl.getInitializer();
125
125
  if (!name.endsWith("_") && !SIMPLE_TRIGGER_FUNCTION_NAMES.includes(name) && initializer && (initializer.getKind() === tsMorph.SyntaxKind.ArrowFunction || initializer.getKind() === tsMorph.SyntaxKind.FunctionExpression)) {
126
- localDeclarations.push(varDecl);
127
- localDeclarationNames.add(name);
128
- methodDefinitions.push(
129
- getInterfaceMethodDefinition_(
130
- name,
131
- initializer
132
- )
133
- );
126
+ const funcExpr = initializer;
127
+ exportedDeclarations.push(varDecl);
128
+ exportedDeclarationNames.add(name);
129
+ methodDefinitions.push(getInterfaceMethodDefinition_(name, funcExpr));
130
+ exportedFunctions.push(funcExpr);
134
131
  }
135
132
  }
136
133
  }
137
134
  }
135
+ const collectSymbolsFromType = (type, foundSymbols) => {
136
+ const symbol = type.getAliasSymbol() ?? type.getSymbol();
137
+ if (symbol && !foundSymbols.has(symbol)) {
138
+ foundSymbols.add(symbol);
139
+ if (type.isObject()) {
140
+ for (const prop of type.getProperties()) {
141
+ const propDecl = prop.getDeclarations()[0];
142
+ if (propDecl) {
143
+ collectSymbolsFromType(propDecl.getType(), foundSymbols);
144
+ }
145
+ }
146
+ }
147
+ }
148
+ for (const typeArg of type.getTypeArguments()) {
149
+ collectSymbolsFromType(typeArg, foundSymbols);
150
+ }
151
+ if (type.isUnion()) {
152
+ for (const unionType of type.getUnionTypes()) {
153
+ collectSymbolsFromType(unionType, foundSymbols);
154
+ }
155
+ }
156
+ if (type.isIntersection()) {
157
+ for (const intersectionType of type.getIntersectionTypes()) {
158
+ collectSymbolsFromType(intersectionType, foundSymbols);
159
+ }
160
+ }
161
+ };
162
+ const returnValueSymbols = /* @__PURE__ */ new Set();
163
+ for (const func of exportedFunctions) {
164
+ collectSymbolsFromType(func.getReturnType(), returnValueSymbols);
165
+ }
138
166
  const importsMap = /* @__PURE__ */ new Map();
139
- for (const decl of localDeclarations) {
140
- const descendants = decl.getDescendantsOfKind?.(tsMorph.SyntaxKind.TypeReference) ?? [];
141
- for (const descendant of descendants) {
167
+ const inlineDefinitions = /* @__PURE__ */ new Map();
168
+ const symbolsToProcess = /* @__PURE__ */ new Set();
169
+ const processedSymbols = /* @__PURE__ */ new Set();
170
+ for (const decl of exportedDeclarations) {
171
+ for (const descendant of decl.getDescendantsOfKind(
172
+ tsMorph.SyntaxKind.TypeReference
173
+ )) {
142
174
  const symbol = descendant.getType().getAliasSymbol() ?? descendant.getType().getSymbol();
143
175
  if (symbol) {
144
- const symbolFlags = symbol.getFlags();
145
- if (symbolFlags & tsMorph.SymbolFlags.TypeParameter) {
146
- continue;
147
- }
148
- const symbolName = symbol.getName();
149
- if (localDeclarationNames.has(symbolName) || symbolName === "__type") {
150
- continue;
151
- }
152
- const declaration = symbol.getDeclarations()[0];
153
- if (declaration) {
154
- const declarationSourceFile = declaration.getSourceFile();
155
- if (declarationSourceFile.getFilePath().includes("node_modules")) {
156
- continue;
157
- }
158
- let modulePath = path__namespace.relative(absoluteOutDir, declarationSourceFile.getFilePath()).replace(/\\/g, "/");
159
- modulePath = modulePath.replace(/\.(d\.)?ts$/, "");
160
- if (modulePath.endsWith("/index")) {
161
- modulePath = modulePath.slice(0, -6);
162
- }
163
- if (modulePath === "index" || modulePath === "") {
164
- modulePath = ".";
165
- }
166
- if (!modulePath.startsWith(".")) {
167
- modulePath = `./${modulePath}`;
168
- }
169
- if (!importsMap.has(modulePath)) {
170
- importsMap.set(modulePath, /* @__PURE__ */ new Set());
176
+ symbolsToProcess.add(symbol);
177
+ }
178
+ }
179
+ }
180
+ while (symbolsToProcess.size > 0) {
181
+ const symbol = symbolsToProcess.values().next().value;
182
+ if (!symbol) continue;
183
+ symbolsToProcess.delete(symbol);
184
+ const symbolName = symbol.getName();
185
+ if (processedSymbols.has(symbolName) || exportedDeclarationNames.has(symbolName) || symbolName === "__type") {
186
+ continue;
187
+ }
188
+ const symbolFlags = symbol.getFlags();
189
+ if (symbolFlags & tsMorph.SymbolFlags.TypeParameter) {
190
+ continue;
191
+ }
192
+ const declaration = symbol.getDeclarations()[0];
193
+ if (!declaration) {
194
+ continue;
195
+ }
196
+ const sourceFile = declaration.getSourceFile();
197
+ if (sourceFile.getFilePath().includes("node_modules")) {
198
+ continue;
199
+ }
200
+ processedSymbols.add(symbolName);
201
+ const isLocalDefinition = declaration.getParent()?.getKind() !== tsMorph.SyntaxKind.SourceFile;
202
+ if (isLocalDefinition) {
203
+ if (returnValueSymbols.has(symbol)) {
204
+ const declText = declaration.getText();
205
+ inlineDefinitions.set(symbolName, declText);
206
+ const tempSourceFile = project.createSourceFile(
207
+ `__temp_${symbolName}.ts`,
208
+ declText
209
+ );
210
+ for (const descendant of tempSourceFile.getDescendantsOfKind(
211
+ tsMorph.SyntaxKind.TypeReference
212
+ )) {
213
+ const newSymbol = descendant.getType().getAliasSymbol() ?? descendant.getType().getSymbol();
214
+ if (newSymbol) {
215
+ symbolsToProcess.add(newSymbol);
171
216
  }
172
- importsMap.get(modulePath)?.add(symbolName);
173
217
  }
218
+ tempSourceFile.delete();
174
219
  }
220
+ } else {
221
+ let modulePath = path__namespace.relative(absoluteOutDir, sourceFile.getFilePath()).replace(/\\/g, "/");
222
+ modulePath = modulePath.replace(/\.(d\.)?ts$/, "");
223
+ if (modulePath.endsWith("/index")) {
224
+ modulePath = modulePath.slice(0, -6);
225
+ }
226
+ if (modulePath === "index" || modulePath === "") {
227
+ modulePath = ".";
228
+ }
229
+ if (!modulePath.startsWith(".")) {
230
+ modulePath = `./${modulePath}`;
231
+ }
232
+ if (!importsMap.has(modulePath)) {
233
+ importsMap.set(modulePath, /* @__PURE__ */ new Set());
234
+ }
235
+ importsMap.get(modulePath)?.add(symbolName);
175
236
  }
176
237
  }
177
238
  if (!fs__namespace.existsSync(absoluteOutDir)) {
@@ -199,11 +260,16 @@ const generateAppsScriptTypes = async ({
199
260
 
200
261
  `;
201
262
  }
202
- const globalTypeDefinitions = localDeclarations.filter(
203
- (d) => d.getKind?.() === tsMorph.SyntaxKind.InterfaceDeclaration || d.getKind?.() === tsMorph.SyntaxKind.TypeAliasDeclaration
204
- ).map((decl) => decl.getText?.());
205
- if (globalTypeDefinitions.length > 0) {
206
- outputContent += `${globalTypeDefinitions.join("\n\n")}
263
+ if (inlineDefinitions.size > 0) {
264
+ outputContent += `${[...inlineDefinitions.values()].join("\n\n")}
265
+
266
+ `;
267
+ }
268
+ const exportedTypeDefinitions = exportedDeclarations.filter(
269
+ (d) => d.getKind() === tsMorph.SyntaxKind.InterfaceDeclaration || d.getKind() === tsMorph.SyntaxKind.TypeAliasDeclaration
270
+ ).map((decl) => decl.getText());
271
+ if (exportedTypeDefinitions.length > 0) {
272
+ outputContent += `${exportedTypeDefinitions.join("\n\n")}
207
273
 
208
274
  `;
209
275
  }
@@ -216,7 +282,7 @@ ${formattedMethods}
216
282
  }
217
283
  `;
218
284
  consola.consola.info(
219
- `Interface 'ServerScript' type definitions written to ${absoluteOutputFile} (${methodDefinitions.length} function(s), ${globalTypeDefinitions.length} type(s)).`
285
+ `Interface 'ServerScript' type definitions written to ${absoluteOutputFile} (${methodDefinitions.length} function(s), ${exportedTypeDefinitions.length + inlineDefinitions.size} type(s)).`
220
286
  );
221
287
  } else {
222
288
  outputContent += "export type ServerScripts = {}\n";
@@ -74,86 +74,147 @@ const generateAppsScriptTypes = async ({
74
74
  const sourceFiles = project.getSourceFiles();
75
75
  consola.info(`Found ${sourceFiles.length} source file(s).`);
76
76
  const methodDefinitions = [];
77
- const localDeclarations = [];
78
- const localDeclarationNames = /* @__PURE__ */ new Set();
77
+ const exportedDeclarations = [];
78
+ const exportedDeclarationNames = /* @__PURE__ */ new Set();
79
+ const exportedFunctions = [];
79
80
  for (const sourceFile of sourceFiles) {
80
81
  for (const iface of sourceFile.getInterfaces()) {
81
- const name = iface.getName?.();
82
- if (name && !name.endsWith("_")) {
83
- localDeclarations.push(iface);
84
- localDeclarationNames.add(name);
82
+ if (iface.isExported() && !iface.getName()?.endsWith("_")) {
83
+ exportedDeclarations.push(iface);
84
+ exportedDeclarationNames.add(iface.getName());
85
85
  }
86
86
  }
87
87
  for (const typeAlias of sourceFile.getTypeAliases()) {
88
- const name = typeAlias.getName();
89
- if (name && !name.endsWith("_")) {
90
- localDeclarations.push(typeAlias);
91
- localDeclarationNames.add(name);
88
+ if (typeAlias.isExported() && !typeAlias.getName().endsWith("_")) {
89
+ exportedDeclarations.push(typeAlias);
90
+ exportedDeclarationNames.add(typeAlias.getName());
92
91
  }
93
92
  }
94
93
  for (const func of sourceFile.getFunctions()) {
95
94
  const name = func.getName();
96
- if (name && !func.isAmbient() && !name.endsWith("_") && !SIMPLE_TRIGGER_FUNCTION_NAMES.includes(name)) {
97
- localDeclarations.push(func);
98
- localDeclarationNames.add(name);
95
+ if (func.isExported() && name && !name.endsWith("_") && !SIMPLE_TRIGGER_FUNCTION_NAMES.includes(name)) {
96
+ exportedDeclarations.push(func);
97
+ exportedDeclarationNames.add(name);
99
98
  methodDefinitions.push(getInterfaceMethodDefinition_(name, func));
99
+ exportedFunctions.push(func);
100
100
  }
101
101
  }
102
102
  for (const varStmt of sourceFile.getVariableStatements()) {
103
- if (varStmt.isAmbient()) continue;
103
+ if (!varStmt.isExported()) continue;
104
104
  for (const varDecl of varStmt.getDeclarations()) {
105
105
  const name = varDecl.getName();
106
106
  const initializer = varDecl.getInitializer();
107
107
  if (!name.endsWith("_") && !SIMPLE_TRIGGER_FUNCTION_NAMES.includes(name) && initializer && (initializer.getKind() === SyntaxKind.ArrowFunction || initializer.getKind() === SyntaxKind.FunctionExpression)) {
108
- localDeclarations.push(varDecl);
109
- localDeclarationNames.add(name);
110
- methodDefinitions.push(
111
- getInterfaceMethodDefinition_(
112
- name,
113
- initializer
114
- )
115
- );
108
+ const funcExpr = initializer;
109
+ exportedDeclarations.push(varDecl);
110
+ exportedDeclarationNames.add(name);
111
+ methodDefinitions.push(getInterfaceMethodDefinition_(name, funcExpr));
112
+ exportedFunctions.push(funcExpr);
116
113
  }
117
114
  }
118
115
  }
119
116
  }
117
+ const collectSymbolsFromType = (type, foundSymbols) => {
118
+ const symbol = type.getAliasSymbol() ?? type.getSymbol();
119
+ if (symbol && !foundSymbols.has(symbol)) {
120
+ foundSymbols.add(symbol);
121
+ if (type.isObject()) {
122
+ for (const prop of type.getProperties()) {
123
+ const propDecl = prop.getDeclarations()[0];
124
+ if (propDecl) {
125
+ collectSymbolsFromType(propDecl.getType(), foundSymbols);
126
+ }
127
+ }
128
+ }
129
+ }
130
+ for (const typeArg of type.getTypeArguments()) {
131
+ collectSymbolsFromType(typeArg, foundSymbols);
132
+ }
133
+ if (type.isUnion()) {
134
+ for (const unionType of type.getUnionTypes()) {
135
+ collectSymbolsFromType(unionType, foundSymbols);
136
+ }
137
+ }
138
+ if (type.isIntersection()) {
139
+ for (const intersectionType of type.getIntersectionTypes()) {
140
+ collectSymbolsFromType(intersectionType, foundSymbols);
141
+ }
142
+ }
143
+ };
144
+ const returnValueSymbols = /* @__PURE__ */ new Set();
145
+ for (const func of exportedFunctions) {
146
+ collectSymbolsFromType(func.getReturnType(), returnValueSymbols);
147
+ }
120
148
  const importsMap = /* @__PURE__ */ new Map();
121
- for (const decl of localDeclarations) {
122
- const descendants = decl.getDescendantsOfKind?.(SyntaxKind.TypeReference) ?? [];
123
- for (const descendant of descendants) {
149
+ const inlineDefinitions = /* @__PURE__ */ new Map();
150
+ const symbolsToProcess = /* @__PURE__ */ new Set();
151
+ const processedSymbols = /* @__PURE__ */ new Set();
152
+ for (const decl of exportedDeclarations) {
153
+ for (const descendant of decl.getDescendantsOfKind(
154
+ SyntaxKind.TypeReference
155
+ )) {
124
156
  const symbol = descendant.getType().getAliasSymbol() ?? descendant.getType().getSymbol();
125
157
  if (symbol) {
126
- const symbolFlags = symbol.getFlags();
127
- if (symbolFlags & SymbolFlags.TypeParameter) {
128
- continue;
129
- }
130
- const symbolName = symbol.getName();
131
- if (localDeclarationNames.has(symbolName) || symbolName === "__type") {
132
- continue;
133
- }
134
- const declaration = symbol.getDeclarations()[0];
135
- if (declaration) {
136
- const declarationSourceFile = declaration.getSourceFile();
137
- if (declarationSourceFile.getFilePath().includes("node_modules")) {
138
- continue;
139
- }
140
- let modulePath = path.relative(absoluteOutDir, declarationSourceFile.getFilePath()).replace(/\\/g, "/");
141
- modulePath = modulePath.replace(/\.(d\.)?ts$/, "");
142
- if (modulePath.endsWith("/index")) {
143
- modulePath = modulePath.slice(0, -6);
144
- }
145
- if (modulePath === "index" || modulePath === "") {
146
- modulePath = ".";
147
- }
148
- if (!modulePath.startsWith(".")) {
149
- modulePath = `./${modulePath}`;
150
- }
151
- if (!importsMap.has(modulePath)) {
152
- importsMap.set(modulePath, /* @__PURE__ */ new Set());
158
+ symbolsToProcess.add(symbol);
159
+ }
160
+ }
161
+ }
162
+ while (symbolsToProcess.size > 0) {
163
+ const symbol = symbolsToProcess.values().next().value;
164
+ if (!symbol) continue;
165
+ symbolsToProcess.delete(symbol);
166
+ const symbolName = symbol.getName();
167
+ if (processedSymbols.has(symbolName) || exportedDeclarationNames.has(symbolName) || symbolName === "__type") {
168
+ continue;
169
+ }
170
+ const symbolFlags = symbol.getFlags();
171
+ if (symbolFlags & SymbolFlags.TypeParameter) {
172
+ continue;
173
+ }
174
+ const declaration = symbol.getDeclarations()[0];
175
+ if (!declaration) {
176
+ continue;
177
+ }
178
+ const sourceFile = declaration.getSourceFile();
179
+ if (sourceFile.getFilePath().includes("node_modules")) {
180
+ continue;
181
+ }
182
+ processedSymbols.add(symbolName);
183
+ const isLocalDefinition = declaration.getParent()?.getKind() !== SyntaxKind.SourceFile;
184
+ if (isLocalDefinition) {
185
+ if (returnValueSymbols.has(symbol)) {
186
+ const declText = declaration.getText();
187
+ inlineDefinitions.set(symbolName, declText);
188
+ const tempSourceFile = project.createSourceFile(
189
+ `__temp_${symbolName}.ts`,
190
+ declText
191
+ );
192
+ for (const descendant of tempSourceFile.getDescendantsOfKind(
193
+ SyntaxKind.TypeReference
194
+ )) {
195
+ const newSymbol = descendant.getType().getAliasSymbol() ?? descendant.getType().getSymbol();
196
+ if (newSymbol) {
197
+ symbolsToProcess.add(newSymbol);
153
198
  }
154
- importsMap.get(modulePath)?.add(symbolName);
155
199
  }
200
+ tempSourceFile.delete();
156
201
  }
202
+ } else {
203
+ let modulePath = path.relative(absoluteOutDir, sourceFile.getFilePath()).replace(/\\/g, "/");
204
+ modulePath = modulePath.replace(/\.(d\.)?ts$/, "");
205
+ if (modulePath.endsWith("/index")) {
206
+ modulePath = modulePath.slice(0, -6);
207
+ }
208
+ if (modulePath === "index" || modulePath === "") {
209
+ modulePath = ".";
210
+ }
211
+ if (!modulePath.startsWith(".")) {
212
+ modulePath = `./${modulePath}`;
213
+ }
214
+ if (!importsMap.has(modulePath)) {
215
+ importsMap.set(modulePath, /* @__PURE__ */ new Set());
216
+ }
217
+ importsMap.get(modulePath)?.add(symbolName);
157
218
  }
158
219
  }
159
220
  if (!fs.existsSync(absoluteOutDir)) {
@@ -181,11 +242,16 @@ const generateAppsScriptTypes = async ({
181
242
 
182
243
  `;
183
244
  }
184
- const globalTypeDefinitions = localDeclarations.filter(
185
- (d) => d.getKind?.() === SyntaxKind.InterfaceDeclaration || d.getKind?.() === SyntaxKind.TypeAliasDeclaration
186
- ).map((decl) => decl.getText?.());
187
- if (globalTypeDefinitions.length > 0) {
188
- outputContent += `${globalTypeDefinitions.join("\n\n")}
245
+ if (inlineDefinitions.size > 0) {
246
+ outputContent += `${[...inlineDefinitions.values()].join("\n\n")}
247
+
248
+ `;
249
+ }
250
+ const exportedTypeDefinitions = exportedDeclarations.filter(
251
+ (d) => d.getKind() === SyntaxKind.InterfaceDeclaration || d.getKind() === SyntaxKind.TypeAliasDeclaration
252
+ ).map((decl) => decl.getText());
253
+ if (exportedTypeDefinitions.length > 0) {
254
+ outputContent += `${exportedTypeDefinitions.join("\n\n")}
189
255
 
190
256
  `;
191
257
  }
@@ -198,7 +264,7 @@ ${formattedMethods}
198
264
  }
199
265
  `;
200
266
  consola.info(
201
- `Interface 'ServerScript' type definitions written to ${absoluteOutputFile} (${methodDefinitions.length} function(s), ${globalTypeDefinitions.length} type(s)).`
267
+ `Interface 'ServerScript' type definitions written to ${absoluteOutputFile} (${methodDefinitions.length} function(s), ${exportedTypeDefinitions.length + inlineDefinitions.size} type(s)).`
202
268
  );
203
269
  } else {
204
270
  outputContent += "export type ServerScripts = {}\n";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ciderjs/gasnuki",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "Type definitions and utilities for Google Apps Script client-side API",
5
5
  "main": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",