@ciderjs/gasnuki 0.3.6 → 0.3.8

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,7 +1,7 @@
1
1
  # @ciderjs/gasnuki
2
2
 
3
3
  [![README-en](https://img.shields.io/badge/English-blue?logo=ReadMe)](./README.md)
4
- [![Test Coverage](https://img.shields.io/badge/test%20coverage-94.74%25-brightgreen)](https://github.com/luthpg/gasnuki)
4
+ [![Test Coverage](https://img.shields.io/badge/test%20coverage-93.63%25-brightgreen)](https://github.com/luthpg/gasnuki)
5
5
  [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
6
6
  [![npm version](https://img.shields.io/npm/v/@ciderjs/gasnuki.svg)](https://www.npmjs.com/package/@ciderjs/gasnuki)
7
7
  [![GitHub issues](https://img.shields.io/github/issues/luthpg/gasnuki.svg)](https://github.com/luthpg/gasnuki/issues)
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @ciderjs/gasnuki
2
2
 
3
3
  [![README-ja](https://img.shields.io/badge/日本語-blue?logo=ReadMe)](./README.ja.md)
4
- [![Test Coverage](https://img.shields.io/badge/test%20coverage-94.74%25-brightgreen)](https://github.com/luthpg/gasnuki)
4
+ [![Test Coverage](https://img.shields.io/badge/test%20coverage-93.63%25-brightgreen)](https://github.com/luthpg/gasnuki)
5
5
  [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
6
6
  [![npm version](https://img.shields.io/npm/v/@ciderjs/gasnuki.svg)](https://www.npmjs.com/package/@ciderjs/gasnuki)
7
7
  [![GitHub issues](https://img.shields.io/github/issues/luthpg/gasnuki.svg)](https://github.com/luthpg/gasnuki/issues)
package/dist/cli.cjs CHANGED
@@ -4,7 +4,7 @@
4
4
  const path = require('node:path');
5
5
  const commander = require('commander');
6
6
  const index = require('./index.cjs');
7
- const config = require('./shared/gasnuki.rciF8k_d.cjs');
7
+ const config = require('./shared/gasnuki.BVdkJsiP.cjs');
8
8
  require('chokidar');
9
9
  require('consola');
10
10
  require('node:fs');
@@ -25,7 +25,7 @@ function _interopNamespaceCompat(e) {
25
25
 
26
26
  const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
27
27
 
28
- const version = "0.3.6";
28
+ const version = "0.3.8";
29
29
 
30
30
  const parseArgs = async (command) => {
31
31
  const cliOpts = command.opts();
package/dist/cli.mjs CHANGED
@@ -2,14 +2,14 @@
2
2
  import * as path from 'node:path';
3
3
  import { Command } from 'commander';
4
4
  import { generateTypes } from './index.mjs';
5
- import { l as loadConfig } from './shared/gasnuki.CfdOhkQS.mjs';
5
+ import { l as loadConfig } from './shared/gasnuki.Cd8JOTQ5.mjs';
6
6
  import 'chokidar';
7
7
  import 'consola';
8
8
  import 'node:fs';
9
9
  import 'ts-morph';
10
10
  import 'jiti';
11
11
 
12
- const version = "0.3.6";
12
+ const version = "0.3.8";
13
13
 
14
14
  const parseArgs = async (command) => {
15
15
  const cliOpts = command.opts();
package/dist/index.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  const path = require('node:path');
4
4
  const chokidar = require('chokidar');
5
5
  const consola = require('consola');
6
- const config = require('./shared/gasnuki.rciF8k_d.cjs');
6
+ const config = require('./shared/gasnuki.BVdkJsiP.cjs');
7
7
  require('node:fs');
8
8
  require('ts-morph');
9
9
  require('jiti');
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as path from 'node:path';
2
2
  import * as chokidar from 'chokidar';
3
3
  import { consola } from 'consola';
4
- import { g as generateAppsScriptTypes } from './shared/gasnuki.CfdOhkQS.mjs';
5
- export { d as defineConfig } from './shared/gasnuki.CfdOhkQS.mjs';
4
+ import { g as generateAppsScriptTypes } from './shared/gasnuki.Cd8JOTQ5.mjs';
5
+ export { d as defineConfig } from './shared/gasnuki.Cd8JOTQ5.mjs';
6
6
  import 'node:fs';
7
7
  import 'ts-morph';
8
8
  import 'jiti';
@@ -58,7 +58,15 @@ const getInterfaceMethodDefinition_ = (name, node) => {
58
58
  `;
59
59
  }
60
60
  }
61
- return `${jsDocString}${name}${typeParamsString}(${parameters}): ${returnType};`;
61
+ const cleanType = (t) => t.replace(/import\(.*?\)\./g, "");
62
+ const cleanedReturnType = cleanType(returnType);
63
+ const cleanedParameters = parameters.replace(
64
+ /:\s*([^,;)]+)/g,
65
+ (_match, p1) => {
66
+ return `: ${cleanType(p1)}`;
67
+ }
68
+ );
69
+ return `${jsDocString}${name}${typeParamsString}(${cleanedParameters}): ${cleanedReturnType};`;
62
70
  };
63
71
  const SIMPLE_TRIGGER_FUNCTION_NAMES = [
64
72
  "onOpen",
@@ -164,16 +172,15 @@ const generateAppsScriptTypes = async ({
164
172
  const declarations = aliasSymbol.getDeclarations();
165
173
  if (declarations.length > 0) {
166
174
  const sourceFilePath = declarations[0].getSourceFile().getFilePath();
167
- const isNodeModules = sourceFilePath.includes("node_modules");
168
- if (isNodeModules) {
175
+ const isExternal = sourceFilePath.includes("node_modules") || !sourceFilePath.replace(/\\/g, "/").startsWith(absoluteSrcDir.replace(/\\/g, "/")) && !sourceFilePath.replace(/\\/g, "/").startsWith(path__namespace.join(projectPath, srcDir).replace(/\\/g, "/"));
176
+ if (isExternal) {
169
177
  foundSymbols.add(aliasSymbol);
178
+ for (const typeArg of type.getAliasTypeArguments()) {
179
+ collectSymbolsFromType(typeArg, foundSymbols);
180
+ }
170
181
  return;
171
182
  }
172
183
  }
173
- foundSymbols.add(aliasSymbol);
174
- for (const typeArg of type.getAliasTypeArguments()) {
175
- collectSymbolsFromType(typeArg, foundSymbols);
176
- }
177
184
  }
178
185
  const symbol = type.getSymbol();
179
186
  let shouldTraverseProperties = true;
@@ -185,7 +192,10 @@ const generateAppsScriptTypes = async ({
185
192
  const declarations = symbol.getDeclarations();
186
193
  if (declarations.length > 0) {
187
194
  const sourceFilePath = declarations[0].getSourceFile().getFilePath();
188
- if (sourceFilePath.includes("node_modules")) {
195
+ const isExternal = sourceFilePath.includes("node_modules") || !sourceFilePath.replace(/\\/g, "/").startsWith(absoluteSrcDir.replace(/\\/g, "/")) && !sourceFilePath.replace(/\\/g, "/").startsWith(
196
+ path__namespace.join(projectPath, srcDir).replace(/\\/g, "/")
197
+ );
198
+ if (isExternal) {
189
199
  shouldTraverseProperties = false;
190
200
  }
191
201
  }
@@ -261,16 +271,35 @@ const generateAppsScriptTypes = async ({
261
271
  if (!declaration) {
262
272
  continue;
263
273
  }
264
- if (declaration.getKind() === tsMorph.SyntaxKind.MethodSignature || declaration.getKind() === tsMorph.SyntaxKind.PropertySignature || declaration.getKind() === tsMorph.SyntaxKind.MethodDeclaration || declaration.getKind() === tsMorph.SyntaxKind.PropertyDeclaration) {
265
- continue;
274
+ const allowedKinds = [
275
+ tsMorph.SyntaxKind.InterfaceDeclaration,
276
+ tsMorph.SyntaxKind.TypeAliasDeclaration,
277
+ tsMorph.SyntaxKind.EnumDeclaration,
278
+ tsMorph.SyntaxKind.ClassDeclaration,
279
+ tsMorph.SyntaxKind.ModuleDeclaration
280
+ ];
281
+ if (!allowedKinds.includes(declaration.getKind())) {
282
+ if (declaration.getKind() === tsMorph.SyntaxKind.VariableDeclaration) {
283
+ const typeNode = declaration.getTypeNode();
284
+ const isUniqueSymbol = typeNode?.getText().includes("unique symbol");
285
+ if (!isUniqueSymbol) {
286
+ continue;
287
+ }
288
+ } else {
289
+ continue;
290
+ }
266
291
  }
267
292
  const sourceFile = declaration.getSourceFile();
268
293
  const sourceFilePath = sourceFile.getFilePath();
269
294
  if (/[/\\]typescript[/\\]lib[/\\]/.test(sourceFilePath)) {
270
295
  continue;
271
296
  }
272
- if (sourceFilePath.includes("node_modules")) {
273
- if (functionSignatureSymbols.has(symbol)) {
297
+ const isExternal = sourceFilePath.includes("node_modules") || !sourceFilePath.replace(/\\/g, "/").startsWith(absoluteSrcDir.replace(/\\/g, "/")) && !sourceFilePath.replace(/\\/g, "/").startsWith(path__namespace.join(projectPath, srcDir).replace(/\\/g, "/"));
298
+ if (isExternal) {
299
+ if (sourceFilePath.includes("node_modules")) {
300
+ if (!functionSignatureSymbols.has(symbol)) {
301
+ continue;
302
+ }
274
303
  const packageName = getPackageNameFromNodeModulesPath_(sourceFilePath);
275
304
  if (packageName) {
276
305
  processedSymbols.add(symbolName);
@@ -279,29 +308,26 @@ const generateAppsScriptTypes = async ({
279
308
  }
280
309
  importsMap.get(packageName)?.add(symbolName);
281
310
  }
311
+ } else {
312
+ let modulePath = path__namespace.relative(absoluteOutDir, sourceFilePath).replace(/\\/g, "/");
313
+ modulePath = modulePath.replace(/\.(d\.)?ts$/, "");
314
+ if (modulePath.endsWith("/index")) {
315
+ modulePath = modulePath.slice(0, -6);
316
+ }
317
+ if (modulePath === "index" || modulePath === "") {
318
+ modulePath = ".";
319
+ }
320
+ if (!modulePath.startsWith(".")) {
321
+ modulePath = `./${modulePath}`;
322
+ }
323
+ if (!importsMap.has(modulePath)) {
324
+ importsMap.set(modulePath, /* @__PURE__ */ new Set());
325
+ }
326
+ importsMap.get(modulePath)?.add(symbolName);
282
327
  }
283
328
  continue;
284
329
  }
285
330
  processedSymbols.add(symbolName);
286
- const isExternal = !sourceFilePath.replace(/\\/g, "/").startsWith(absoluteSrcDir.replace(/\\/g, "/")) && !sourceFilePath.replace(/\\/g, "/").startsWith(path__namespace.join(projectPath, srcDir).replace(/\\/g, "/"));
287
- if (isExternal) {
288
- let modulePath = path__namespace.relative(absoluteOutDir, sourceFilePath).replace(/\\/g, "/");
289
- modulePath = modulePath.replace(/\.(d\.)?ts$/, "");
290
- if (modulePath.endsWith("/index")) {
291
- modulePath = modulePath.slice(0, -6);
292
- }
293
- if (modulePath === "index" || modulePath === "") {
294
- modulePath = ".";
295
- }
296
- if (!modulePath.startsWith(".")) {
297
- modulePath = `./${modulePath}`;
298
- }
299
- if (!importsMap.has(modulePath)) {
300
- importsMap.set(modulePath, /* @__PURE__ */ new Set());
301
- }
302
- importsMap.get(modulePath)?.add(symbolName);
303
- continue;
304
- }
305
331
  let declText = declaration.getText();
306
332
  if (declaration.getKind() === tsMorph.SyntaxKind.VariableDeclaration) {
307
333
  const variableStatement = declaration.getParent()?.getParent();
@@ -328,24 +354,9 @@ const generateAppsScriptTypes = async ({
328
354
  // Do NOT edit this file manually.
329
355
 
330
356
  `;
331
- const sortedModulePaths = [...importsMap.keys()].sort((a, b) => {
332
- const aIsRelative = a.startsWith(".");
333
- const bIsRelative = b.startsWith(".");
334
- if (aIsRelative !== bIsRelative) return aIsRelative ? 1 : -1;
335
- return a.localeCompare(b);
336
- });
337
- if (sortedModulePaths.length > 0) {
338
- const importStatements = sortedModulePaths.map((modulePath) => {
339
- const imports = [...importsMap.get(modulePath) ?? []].sort();
340
- const finalModulePath = modulePath === "." ? "./index" : modulePath;
341
- return `import type { ${imports.join(", ")} } from '${finalModulePath}';`;
342
- });
343
- outputContent += `${importStatements.join("\n")}
344
-
345
- `;
346
- }
357
+ let bodyContent = "";
347
358
  if (inlineDefinitions.size > 0) {
348
- outputContent += `${[...inlineDefinitions.values()].join("\n\n")}
359
+ bodyContent += `${[...inlineDefinitions.values()].join("\n\n")}
349
360
 
350
361
  `;
351
362
  }
@@ -353,7 +364,7 @@ const generateAppsScriptTypes = async ({
353
364
  (d) => d.getKind() === tsMorph.SyntaxKind.InterfaceDeclaration || d.getKind() === tsMorph.SyntaxKind.TypeAliasDeclaration
354
365
  ).map((decl) => decl.getText());
355
366
  if (exportedTypeDefinitions.length > 0) {
356
- outputContent += `${exportedTypeDefinitions.join("\n\n")}
367
+ bodyContent += `${exportedTypeDefinitions.join("\n\n")}
357
368
 
358
369
  `;
359
370
  }
@@ -361,7 +372,7 @@ const generateAppsScriptTypes = async ({
361
372
  const formattedMethods = methodDefinitions.map(
362
373
  (method) => method.split("\n").map((line) => ` ${line}`).join("\n")
363
374
  ).join("\n\n");
364
- outputContent += `export type ServerScripts = {
375
+ bodyContent += `export type ServerScripts = {
365
376
  ${formattedMethods}
366
377
  }
367
378
  `;
@@ -369,15 +380,40 @@ ${formattedMethods}
369
380
  `Interface 'ServerScript' type definitions written to ${absoluteOutputFile} (${methodDefinitions.length} function(s), ${exportedTypeDefinitions.length + inlineDefinitions.size} type(s)).`
370
381
  );
371
382
  } else {
372
- outputContent += "export type ServerScripts = {}\n";
383
+ bodyContent += "export type ServerScripts = {}\n";
373
384
  consola.consola.info(
374
385
  `Interface 'ServerScript' type definitions written to ${absoluteOutputFile} (no functions found).`
375
386
  );
376
387
  }
377
- outputContent += `
388
+ bodyContent += `
378
389
  // Auto-generated Types for GoogleAppsScript in client-side code
379
390
 
380
391
  ${text}`;
392
+ const sortedModulePaths = [...importsMap.keys()].sort((a, b) => {
393
+ const aIsRelative = a.startsWith(".");
394
+ const bIsRelative = b.startsWith(".");
395
+ if (aIsRelative !== bIsRelative) return aIsRelative ? 1 : -1;
396
+ return a.localeCompare(b);
397
+ });
398
+ if (sortedModulePaths.length > 0) {
399
+ const importStatements = sortedModulePaths.map((modulePath) => {
400
+ const imports = [...importsMap.get(modulePath) ?? []].sort().filter((importName) => {
401
+ const regex = new RegExp(`\\b${importName}\\b`);
402
+ return regex.test(bodyContent);
403
+ });
404
+ if (imports.length === 0) {
405
+ return null;
406
+ }
407
+ const finalModulePath = modulePath === "." ? "./index" : modulePath;
408
+ return `import type { ${imports.join(", ")} } from '${finalModulePath}';`;
409
+ }).filter((s) => s !== null);
410
+ if (importStatements.length > 0) {
411
+ outputContent += `${importStatements.join("\n")}
412
+
413
+ `;
414
+ }
415
+ }
416
+ outputContent += bodyContent;
381
417
  fs__namespace.writeFileSync(absoluteOutputFile, outputContent);
382
418
  };
383
419
 
@@ -41,7 +41,15 @@ const getInterfaceMethodDefinition_ = (name, node) => {
41
41
  `;
42
42
  }
43
43
  }
44
- return `${jsDocString}${name}${typeParamsString}(${parameters}): ${returnType};`;
44
+ const cleanType = (t) => t.replace(/import\(.*?\)\./g, "");
45
+ const cleanedReturnType = cleanType(returnType);
46
+ const cleanedParameters = parameters.replace(
47
+ /:\s*([^,;)]+)/g,
48
+ (_match, p1) => {
49
+ return `: ${cleanType(p1)}`;
50
+ }
51
+ );
52
+ return `${jsDocString}${name}${typeParamsString}(${cleanedParameters}): ${cleanedReturnType};`;
45
53
  };
46
54
  const SIMPLE_TRIGGER_FUNCTION_NAMES = [
47
55
  "onOpen",
@@ -147,16 +155,15 @@ const generateAppsScriptTypes = async ({
147
155
  const declarations = aliasSymbol.getDeclarations();
148
156
  if (declarations.length > 0) {
149
157
  const sourceFilePath = declarations[0].getSourceFile().getFilePath();
150
- const isNodeModules = sourceFilePath.includes("node_modules");
151
- if (isNodeModules) {
158
+ const isExternal = sourceFilePath.includes("node_modules") || !sourceFilePath.replace(/\\/g, "/").startsWith(absoluteSrcDir.replace(/\\/g, "/")) && !sourceFilePath.replace(/\\/g, "/").startsWith(path.join(projectPath, srcDir).replace(/\\/g, "/"));
159
+ if (isExternal) {
152
160
  foundSymbols.add(aliasSymbol);
161
+ for (const typeArg of type.getAliasTypeArguments()) {
162
+ collectSymbolsFromType(typeArg, foundSymbols);
163
+ }
153
164
  return;
154
165
  }
155
166
  }
156
- foundSymbols.add(aliasSymbol);
157
- for (const typeArg of type.getAliasTypeArguments()) {
158
- collectSymbolsFromType(typeArg, foundSymbols);
159
- }
160
167
  }
161
168
  const symbol = type.getSymbol();
162
169
  let shouldTraverseProperties = true;
@@ -168,7 +175,10 @@ const generateAppsScriptTypes = async ({
168
175
  const declarations = symbol.getDeclarations();
169
176
  if (declarations.length > 0) {
170
177
  const sourceFilePath = declarations[0].getSourceFile().getFilePath();
171
- if (sourceFilePath.includes("node_modules")) {
178
+ const isExternal = sourceFilePath.includes("node_modules") || !sourceFilePath.replace(/\\/g, "/").startsWith(absoluteSrcDir.replace(/\\/g, "/")) && !sourceFilePath.replace(/\\/g, "/").startsWith(
179
+ path.join(projectPath, srcDir).replace(/\\/g, "/")
180
+ );
181
+ if (isExternal) {
172
182
  shouldTraverseProperties = false;
173
183
  }
174
184
  }
@@ -244,16 +254,35 @@ const generateAppsScriptTypes = async ({
244
254
  if (!declaration) {
245
255
  continue;
246
256
  }
247
- if (declaration.getKind() === SyntaxKind.MethodSignature || declaration.getKind() === SyntaxKind.PropertySignature || declaration.getKind() === SyntaxKind.MethodDeclaration || declaration.getKind() === SyntaxKind.PropertyDeclaration) {
248
- continue;
257
+ const allowedKinds = [
258
+ SyntaxKind.InterfaceDeclaration,
259
+ SyntaxKind.TypeAliasDeclaration,
260
+ SyntaxKind.EnumDeclaration,
261
+ SyntaxKind.ClassDeclaration,
262
+ SyntaxKind.ModuleDeclaration
263
+ ];
264
+ if (!allowedKinds.includes(declaration.getKind())) {
265
+ if (declaration.getKind() === SyntaxKind.VariableDeclaration) {
266
+ const typeNode = declaration.getTypeNode();
267
+ const isUniqueSymbol = typeNode?.getText().includes("unique symbol");
268
+ if (!isUniqueSymbol) {
269
+ continue;
270
+ }
271
+ } else {
272
+ continue;
273
+ }
249
274
  }
250
275
  const sourceFile = declaration.getSourceFile();
251
276
  const sourceFilePath = sourceFile.getFilePath();
252
277
  if (/[/\\]typescript[/\\]lib[/\\]/.test(sourceFilePath)) {
253
278
  continue;
254
279
  }
255
- if (sourceFilePath.includes("node_modules")) {
256
- if (functionSignatureSymbols.has(symbol)) {
280
+ const isExternal = sourceFilePath.includes("node_modules") || !sourceFilePath.replace(/\\/g, "/").startsWith(absoluteSrcDir.replace(/\\/g, "/")) && !sourceFilePath.replace(/\\/g, "/").startsWith(path.join(projectPath, srcDir).replace(/\\/g, "/"));
281
+ if (isExternal) {
282
+ if (sourceFilePath.includes("node_modules")) {
283
+ if (!functionSignatureSymbols.has(symbol)) {
284
+ continue;
285
+ }
257
286
  const packageName = getPackageNameFromNodeModulesPath_(sourceFilePath);
258
287
  if (packageName) {
259
288
  processedSymbols.add(symbolName);
@@ -262,29 +291,26 @@ const generateAppsScriptTypes = async ({
262
291
  }
263
292
  importsMap.get(packageName)?.add(symbolName);
264
293
  }
294
+ } else {
295
+ let modulePath = path.relative(absoluteOutDir, sourceFilePath).replace(/\\/g, "/");
296
+ modulePath = modulePath.replace(/\.(d\.)?ts$/, "");
297
+ if (modulePath.endsWith("/index")) {
298
+ modulePath = modulePath.slice(0, -6);
299
+ }
300
+ if (modulePath === "index" || modulePath === "") {
301
+ modulePath = ".";
302
+ }
303
+ if (!modulePath.startsWith(".")) {
304
+ modulePath = `./${modulePath}`;
305
+ }
306
+ if (!importsMap.has(modulePath)) {
307
+ importsMap.set(modulePath, /* @__PURE__ */ new Set());
308
+ }
309
+ importsMap.get(modulePath)?.add(symbolName);
265
310
  }
266
311
  continue;
267
312
  }
268
313
  processedSymbols.add(symbolName);
269
- const isExternal = !sourceFilePath.replace(/\\/g, "/").startsWith(absoluteSrcDir.replace(/\\/g, "/")) && !sourceFilePath.replace(/\\/g, "/").startsWith(path.join(projectPath, srcDir).replace(/\\/g, "/"));
270
- if (isExternal) {
271
- let modulePath = path.relative(absoluteOutDir, sourceFilePath).replace(/\\/g, "/");
272
- modulePath = modulePath.replace(/\.(d\.)?ts$/, "");
273
- if (modulePath.endsWith("/index")) {
274
- modulePath = modulePath.slice(0, -6);
275
- }
276
- if (modulePath === "index" || modulePath === "") {
277
- modulePath = ".";
278
- }
279
- if (!modulePath.startsWith(".")) {
280
- modulePath = `./${modulePath}`;
281
- }
282
- if (!importsMap.has(modulePath)) {
283
- importsMap.set(modulePath, /* @__PURE__ */ new Set());
284
- }
285
- importsMap.get(modulePath)?.add(symbolName);
286
- continue;
287
- }
288
314
  let declText = declaration.getText();
289
315
  if (declaration.getKind() === SyntaxKind.VariableDeclaration) {
290
316
  const variableStatement = declaration.getParent()?.getParent();
@@ -311,24 +337,9 @@ const generateAppsScriptTypes = async ({
311
337
  // Do NOT edit this file manually.
312
338
 
313
339
  `;
314
- const sortedModulePaths = [...importsMap.keys()].sort((a, b) => {
315
- const aIsRelative = a.startsWith(".");
316
- const bIsRelative = b.startsWith(".");
317
- if (aIsRelative !== bIsRelative) return aIsRelative ? 1 : -1;
318
- return a.localeCompare(b);
319
- });
320
- if (sortedModulePaths.length > 0) {
321
- const importStatements = sortedModulePaths.map((modulePath) => {
322
- const imports = [...importsMap.get(modulePath) ?? []].sort();
323
- const finalModulePath = modulePath === "." ? "./index" : modulePath;
324
- return `import type { ${imports.join(", ")} } from '${finalModulePath}';`;
325
- });
326
- outputContent += `${importStatements.join("\n")}
327
-
328
- `;
329
- }
340
+ let bodyContent = "";
330
341
  if (inlineDefinitions.size > 0) {
331
- outputContent += `${[...inlineDefinitions.values()].join("\n\n")}
342
+ bodyContent += `${[...inlineDefinitions.values()].join("\n\n")}
332
343
 
333
344
  `;
334
345
  }
@@ -336,7 +347,7 @@ const generateAppsScriptTypes = async ({
336
347
  (d) => d.getKind() === SyntaxKind.InterfaceDeclaration || d.getKind() === SyntaxKind.TypeAliasDeclaration
337
348
  ).map((decl) => decl.getText());
338
349
  if (exportedTypeDefinitions.length > 0) {
339
- outputContent += `${exportedTypeDefinitions.join("\n\n")}
350
+ bodyContent += `${exportedTypeDefinitions.join("\n\n")}
340
351
 
341
352
  `;
342
353
  }
@@ -344,7 +355,7 @@ const generateAppsScriptTypes = async ({
344
355
  const formattedMethods = methodDefinitions.map(
345
356
  (method) => method.split("\n").map((line) => ` ${line}`).join("\n")
346
357
  ).join("\n\n");
347
- outputContent += `export type ServerScripts = {
358
+ bodyContent += `export type ServerScripts = {
348
359
  ${formattedMethods}
349
360
  }
350
361
  `;
@@ -352,15 +363,40 @@ ${formattedMethods}
352
363
  `Interface 'ServerScript' type definitions written to ${absoluteOutputFile} (${methodDefinitions.length} function(s), ${exportedTypeDefinitions.length + inlineDefinitions.size} type(s)).`
353
364
  );
354
365
  } else {
355
- outputContent += "export type ServerScripts = {}\n";
366
+ bodyContent += "export type ServerScripts = {}\n";
356
367
  consola.info(
357
368
  `Interface 'ServerScript' type definitions written to ${absoluteOutputFile} (no functions found).`
358
369
  );
359
370
  }
360
- outputContent += `
371
+ bodyContent += `
361
372
  // Auto-generated Types for GoogleAppsScript in client-side code
362
373
 
363
374
  ${text}`;
375
+ const sortedModulePaths = [...importsMap.keys()].sort((a, b) => {
376
+ const aIsRelative = a.startsWith(".");
377
+ const bIsRelative = b.startsWith(".");
378
+ if (aIsRelative !== bIsRelative) return aIsRelative ? 1 : -1;
379
+ return a.localeCompare(b);
380
+ });
381
+ if (sortedModulePaths.length > 0) {
382
+ const importStatements = sortedModulePaths.map((modulePath) => {
383
+ const imports = [...importsMap.get(modulePath) ?? []].sort().filter((importName) => {
384
+ const regex = new RegExp(`\\b${importName}\\b`);
385
+ return regex.test(bodyContent);
386
+ });
387
+ if (imports.length === 0) {
388
+ return null;
389
+ }
390
+ const finalModulePath = modulePath === "." ? "./index" : modulePath;
391
+ return `import type { ${imports.join(", ")} } from '${finalModulePath}';`;
392
+ }).filter((s) => s !== null);
393
+ if (importStatements.length > 0) {
394
+ outputContent += `${importStatements.join("\n")}
395
+
396
+ `;
397
+ }
398
+ }
399
+ outputContent += bodyContent;
364
400
  fs.writeFileSync(absoluteOutputFile, outputContent);
365
401
  };
366
402
 
package/dist/vite.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  const path = require('node:path');
4
4
  const consola = require('consola');
5
- const config = require('./shared/gasnuki.rciF8k_d.cjs');
5
+ const config = require('./shared/gasnuki.BVdkJsiP.cjs');
6
6
  require('node:fs');
7
7
  require('ts-morph');
8
8
  require('jiti');
package/dist/vite.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as path from 'node:path';
2
2
  import { consola } from 'consola';
3
- import { l as loadConfig, g as generateAppsScriptTypes } from './shared/gasnuki.CfdOhkQS.mjs';
3
+ import { l as loadConfig, g as generateAppsScriptTypes } from './shared/gasnuki.Cd8JOTQ5.mjs';
4
4
  import 'node:fs';
5
5
  import 'ts-morph';
6
6
  import 'jiti';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ciderjs/gasnuki",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
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",