@ciderjs/gasnuki 0.5.0 → 0.5.2

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-93.03%25-brightgreen)](https://github.com/luthpg/gasnuki)
4
+ [![Test Coverage](https://img.shields.io/badge/test%20coverage-89.07%25-green)](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
  ![NPM Downloads](https://img.shields.io/npm/dw/@ciderjs/gasnuki)
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-93.03%25-brightgreen)](https://github.com/luthpg/gasnuki)
4
+ [![Test Coverage](https://img.shields.io/badge/test%20coverage-89.07%25-green)](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
  ![NPM Downloads](https://img.shields.io/npm/dw/@ciderjs/gasnuki)
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.Co0-wxJi.cjs');
7
+ const config = require('./shared/gasnuki.Clw_jH65.cjs');
8
8
  require('chokidar');
9
9
  require('consola');
10
10
  require('node:crypto');
@@ -26,7 +26,7 @@ function _interopNamespaceCompat(e) {
26
26
 
27
27
  const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
28
28
 
29
- const version = "0.5.0";
29
+ const version = "0.5.2";
30
30
 
31
31
  const parseArgs = async (command) => {
32
32
  const cliOpts = command.opts();
package/dist/cli.mjs CHANGED
@@ -2,7 +2,7 @@
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.DePJgSg9.mjs';
5
+ import { l as loadConfig } from './shared/gasnuki.CYbD-wKI.mjs';
6
6
  import 'chokidar';
7
7
  import 'consola';
8
8
  import 'node:crypto';
@@ -10,7 +10,7 @@ import 'node:fs';
10
10
  import 'ts-morph';
11
11
  import 'jiti';
12
12
 
13
- const version = "0.5.0";
13
+ const version = "0.5.2";
14
14
 
15
15
  const parseArgs = async (command) => {
16
16
  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.Co0-wxJi.cjs');
6
+ const config = require('./shared/gasnuki.Clw_jH65.cjs');
7
7
  require('node:crypto');
8
8
  require('node:fs');
9
9
  require('ts-morph');
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.DePJgSg9.mjs';
5
- export { d as defineConfig } from './shared/gasnuki.DePJgSg9.mjs';
4
+ import { g as generateAppsScriptTypes } from './shared/gasnuki.CYbD-wKI.mjs';
5
+ export { d as defineConfig } from './shared/gasnuki.CYbD-wKI.mjs';
6
6
  import 'node:crypto';
7
7
  import 'node:fs';
8
8
  import 'ts-morph';
package/dist/promise.cjs CHANGED
@@ -7,7 +7,24 @@ function getPromisedServerScripts(options = {}) {
7
7
  return new Proxy(mockupFunctions, {
8
8
  get(target, method) {
9
9
  if (!("google" in globalThis) || !google?.script?.run) {
10
- return target[method];
10
+ const mockFunc = target[method];
11
+ if (!mockFunc) {
12
+ return void 0;
13
+ }
14
+ if (!parseJson) {
15
+ return mockFunc;
16
+ }
17
+ return async (...args) => {
18
+ const res = await mockFunc(...args);
19
+ if (typeof res === "string") {
20
+ try {
21
+ return json.deserialize(res);
22
+ } catch {
23
+ return res;
24
+ }
25
+ }
26
+ return res;
27
+ };
11
28
  }
12
29
  if (!(method in google.script.run)) {
13
30
  throw Error(`Method ${method} not found in AppsScript.`);
@@ -10,7 +10,7 @@ type PromisedWithJson<T> = {
10
10
  type PartialScriptType<T> = Partial<Promised<T>>;
11
11
  type PartialScriptTypeWithJson<T> = Partial<PromisedWithJson<T>>;
12
12
  type GetPromisedServerScriptsOptions<T, IsJson extends boolean = boolean> = {
13
- mockupFunctions?: IsJson extends true ? PartialScriptTypeWithJson<T> : PartialScriptType<T>;
13
+ mockupFunctions?: PartialScriptType<T>;
14
14
  parseJson?: IsJson;
15
15
  };
16
16
  declare function getPromisedServerScripts<T extends Record<string, (...args: any[]) => any> = Omit<typeof google.script.run, 'withSuccessHandler' | 'withFailureHandler' | 'withUserObject'>>(options: GetPromisedServerScriptsOptions<T, true>): PromisedWithJson<T>;
@@ -10,7 +10,7 @@ type PromisedWithJson<T> = {
10
10
  type PartialScriptType<T> = Partial<Promised<T>>;
11
11
  type PartialScriptTypeWithJson<T> = Partial<PromisedWithJson<T>>;
12
12
  type GetPromisedServerScriptsOptions<T, IsJson extends boolean = boolean> = {
13
- mockupFunctions?: IsJson extends true ? PartialScriptTypeWithJson<T> : PartialScriptType<T>;
13
+ mockupFunctions?: PartialScriptType<T>;
14
14
  parseJson?: IsJson;
15
15
  };
16
16
  declare function getPromisedServerScripts<T extends Record<string, (...args: any[]) => any> = Omit<typeof google.script.run, 'withSuccessHandler' | 'withFailureHandler' | 'withUserObject'>>(options: GetPromisedServerScriptsOptions<T, true>): PromisedWithJson<T>;
package/dist/promise.d.ts CHANGED
@@ -10,7 +10,7 @@ type PromisedWithJson<T> = {
10
10
  type PartialScriptType<T> = Partial<Promised<T>>;
11
11
  type PartialScriptTypeWithJson<T> = Partial<PromisedWithJson<T>>;
12
12
  type GetPromisedServerScriptsOptions<T, IsJson extends boolean = boolean> = {
13
- mockupFunctions?: IsJson extends true ? PartialScriptTypeWithJson<T> : PartialScriptType<T>;
13
+ mockupFunctions?: PartialScriptType<T>;
14
14
  parseJson?: IsJson;
15
15
  };
16
16
  declare function getPromisedServerScripts<T extends Record<string, (...args: any[]) => any> = Omit<typeof google.script.run, 'withSuccessHandler' | 'withFailureHandler' | 'withUserObject'>>(options: GetPromisedServerScriptsOptions<T, true>): PromisedWithJson<T>;
package/dist/promise.mjs CHANGED
@@ -5,7 +5,24 @@ function getPromisedServerScripts(options = {}) {
5
5
  return new Proxy(mockupFunctions, {
6
6
  get(target, method) {
7
7
  if (!("google" in globalThis) || !google?.script?.run) {
8
- return target[method];
8
+ const mockFunc = target[method];
9
+ if (!mockFunc) {
10
+ return void 0;
11
+ }
12
+ if (!parseJson) {
13
+ return mockFunc;
14
+ }
15
+ return async (...args) => {
16
+ const res = await mockFunc(...args);
17
+ if (typeof res === "string") {
18
+ try {
19
+ return deserialize(res);
20
+ } catch {
21
+ return res;
22
+ }
23
+ }
24
+ return res;
25
+ };
9
26
  }
10
27
  if (!(method in google.script.run)) {
11
28
  throw Error(`Method ${method} not found in AppsScript.`);
@@ -72,27 +72,86 @@ const SIMPLE_TRIGGER_FUNCTION_NAMES = [
72
72
  "doGet",
73
73
  "doPost"
74
74
  ];
75
- const getPackageNameFromNodeModulesPath_ = (filePath) => {
76
- const normalizedPath = filePath.replace(/\\/g, "/");
77
- const nodeModulesIndex = normalizedPath.lastIndexOf("node_modules/");
78
- if (nodeModulesIndex === -1) {
79
- return null;
75
+ const packageJsonCache = /* @__PURE__ */ new Map();
76
+ const findPackageJson_ = (startDir) => {
77
+ let currentDir = startDir;
78
+ while (true) {
79
+ if (packageJsonCache.has(currentDir)) {
80
+ return packageJsonCache.get(currentDir);
81
+ }
82
+ const pkgPath = path.join(currentDir, "package.json");
83
+ if (fs.existsSync(pkgPath)) {
84
+ try {
85
+ const content = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
86
+ const result = { path: pkgPath, content };
87
+ packageJsonCache.set(currentDir, result);
88
+ if (currentDir !== startDir) {
89
+ packageJsonCache.set(startDir, result);
90
+ }
91
+ return result;
92
+ } catch {
93
+ }
94
+ }
95
+ const parentDir = path.dirname(currentDir);
96
+ if (parentDir === currentDir) {
97
+ packageJsonCache.set(currentDir, null);
98
+ if (currentDir !== startDir) {
99
+ packageJsonCache.set(startDir, null);
100
+ }
101
+ break;
102
+ }
103
+ currentDir = parentDir;
80
104
  }
81
- const afterNodeModules = normalizedPath.slice(
82
- nodeModulesIndex + "node_modules/".length
83
- );
84
- const parts = afterNodeModules.split("/");
85
- if (parts.length === 0) {
86
- return null;
105
+ return null;
106
+ };
107
+ const matchesExportValue_ = (node, targetPath) => {
108
+ if (typeof node === "string") {
109
+ return node === targetPath || node === targetPath.replace(/\.d\.ts$/, ".js");
110
+ }
111
+ if (typeof node === "object" && node !== null) {
112
+ if (node.types && node.types === targetPath) {
113
+ return true;
114
+ }
115
+ for (const key in node) {
116
+ if (matchesExportValue_(node[key], targetPath)) {
117
+ return true;
118
+ }
119
+ }
120
+ }
121
+ return false;
122
+ };
123
+ const resolveNodeModuleSpecifier_ = (filePath) => {
124
+ const pkg = findPackageJson_(path.dirname(filePath));
125
+ if (!pkg) return null;
126
+ let packageName = pkg.content.name;
127
+ if (packageName.startsWith("@types/")) {
128
+ packageName = packageName.slice(7);
129
+ }
130
+ const packageRoot = path.dirname(pkg.path);
131
+ let relativePath = path.relative(packageRoot, filePath).replace(/\\/g, "/");
132
+ if (!relativePath.startsWith(".")) {
133
+ relativePath = `./${relativePath}`;
87
134
  }
88
- if (parts[0].startsWith("@") && parts.length >= 2) {
89
- const scopedName = `${parts[0]}/${parts[1]}`;
90
- if (parts[0] === "@types") {
91
- return parts[1];
135
+ if (pkg.content.exports) {
136
+ for (const key in pkg.content.exports) {
137
+ const exportValue = pkg.content.exports[key];
138
+ if (matchesExportValue_(exportValue, relativePath)) {
139
+ if (key === ".") return packageName;
140
+ return path.posix.join(packageName, key);
141
+ }
92
142
  }
93
- return scopedName;
94
143
  }
95
- return parts[0];
144
+ const mainTypes = pkg.content.types || pkg.content.typings;
145
+ if (mainTypes) {
146
+ let normalizedMain = mainTypes.replace(/\\/g, "/");
147
+ if (!normalizedMain.startsWith(".")) {
148
+ normalizedMain = `./${normalizedMain}`;
149
+ }
150
+ if (normalizedMain === relativePath) {
151
+ return packageName;
152
+ }
153
+ }
154
+ return packageName;
96
155
  };
97
156
  const generateAppsScriptTypes = async ({
98
157
  project: projectPath,
@@ -109,8 +168,12 @@ const generateAppsScriptTypes = async ({
109
168
  consola.info("Starting AppsScript type generation with gasnuki...");
110
169
  consola.info(` AppsScript Source Directory: ${absoluteSrcDir}`);
111
170
  consola.info(` Output File: ${absoluteOutputFile}`);
171
+ let tsConfigFilePath = path.resolve(projectPath, "tsconfig.json");
172
+ if (fs.existsSync(path.resolve(projectPath, "tsconfig.app.json"))) {
173
+ tsConfigFilePath = path.resolve(projectPath, "tsconfig.app.json");
174
+ }
112
175
  const project = projectInstance ?? new Project({
113
- tsConfigFilePath: path.resolve(projectPath, "tsconfig.json"),
176
+ tsConfigFilePath,
114
177
  skipAddingFilesFromTsConfig: true
115
178
  });
116
179
  const sourceFilesPattern = path.join(absoluteSrcDir, "**/*.ts").replace(/\\/g, "/");
@@ -407,7 +470,7 @@ const generateAppsScriptTypes = async ({
407
470
  if (!functionSignatureSymbols.has(symbol)) {
408
471
  continue;
409
472
  }
410
- const packageName = getPackageNameFromNodeModulesPath_(sourceFilePath);
473
+ const packageName = resolveNodeModuleSpecifier_(sourceFilePath);
411
474
  if (packageName) {
412
475
  processedSymbols.add(symbolName);
413
476
  if (!importsMap.has(packageName)) {
@@ -90,27 +90,86 @@ const SIMPLE_TRIGGER_FUNCTION_NAMES = [
90
90
  "doGet",
91
91
  "doPost"
92
92
  ];
93
- const getPackageNameFromNodeModulesPath_ = (filePath) => {
94
- const normalizedPath = filePath.replace(/\\/g, "/");
95
- const nodeModulesIndex = normalizedPath.lastIndexOf("node_modules/");
96
- if (nodeModulesIndex === -1) {
97
- return null;
93
+ const packageJsonCache = /* @__PURE__ */ new Map();
94
+ const findPackageJson_ = (startDir) => {
95
+ let currentDir = startDir;
96
+ while (true) {
97
+ if (packageJsonCache.has(currentDir)) {
98
+ return packageJsonCache.get(currentDir);
99
+ }
100
+ const pkgPath = path__namespace.join(currentDir, "package.json");
101
+ if (fs__namespace.existsSync(pkgPath)) {
102
+ try {
103
+ const content = JSON.parse(fs__namespace.readFileSync(pkgPath, "utf-8"));
104
+ const result = { path: pkgPath, content };
105
+ packageJsonCache.set(currentDir, result);
106
+ if (currentDir !== startDir) {
107
+ packageJsonCache.set(startDir, result);
108
+ }
109
+ return result;
110
+ } catch {
111
+ }
112
+ }
113
+ const parentDir = path__namespace.dirname(currentDir);
114
+ if (parentDir === currentDir) {
115
+ packageJsonCache.set(currentDir, null);
116
+ if (currentDir !== startDir) {
117
+ packageJsonCache.set(startDir, null);
118
+ }
119
+ break;
120
+ }
121
+ currentDir = parentDir;
98
122
  }
99
- const afterNodeModules = normalizedPath.slice(
100
- nodeModulesIndex + "node_modules/".length
101
- );
102
- const parts = afterNodeModules.split("/");
103
- if (parts.length === 0) {
104
- return null;
123
+ return null;
124
+ };
125
+ const matchesExportValue_ = (node, targetPath) => {
126
+ if (typeof node === "string") {
127
+ return node === targetPath || node === targetPath.replace(/\.d\.ts$/, ".js");
128
+ }
129
+ if (typeof node === "object" && node !== null) {
130
+ if (node.types && node.types === targetPath) {
131
+ return true;
132
+ }
133
+ for (const key in node) {
134
+ if (matchesExportValue_(node[key], targetPath)) {
135
+ return true;
136
+ }
137
+ }
138
+ }
139
+ return false;
140
+ };
141
+ const resolveNodeModuleSpecifier_ = (filePath) => {
142
+ const pkg = findPackageJson_(path__namespace.dirname(filePath));
143
+ if (!pkg) return null;
144
+ let packageName = pkg.content.name;
145
+ if (packageName.startsWith("@types/")) {
146
+ packageName = packageName.slice(7);
147
+ }
148
+ const packageRoot = path__namespace.dirname(pkg.path);
149
+ let relativePath = path__namespace.relative(packageRoot, filePath).replace(/\\/g, "/");
150
+ if (!relativePath.startsWith(".")) {
151
+ relativePath = `./${relativePath}`;
105
152
  }
106
- if (parts[0].startsWith("@") && parts.length >= 2) {
107
- const scopedName = `${parts[0]}/${parts[1]}`;
108
- if (parts[0] === "@types") {
109
- return parts[1];
153
+ if (pkg.content.exports) {
154
+ for (const key in pkg.content.exports) {
155
+ const exportValue = pkg.content.exports[key];
156
+ if (matchesExportValue_(exportValue, relativePath)) {
157
+ if (key === ".") return packageName;
158
+ return path__namespace.posix.join(packageName, key);
159
+ }
110
160
  }
111
- return scopedName;
112
161
  }
113
- return parts[0];
162
+ const mainTypes = pkg.content.types || pkg.content.typings;
163
+ if (mainTypes) {
164
+ let normalizedMain = mainTypes.replace(/\\/g, "/");
165
+ if (!normalizedMain.startsWith(".")) {
166
+ normalizedMain = `./${normalizedMain}`;
167
+ }
168
+ if (normalizedMain === relativePath) {
169
+ return packageName;
170
+ }
171
+ }
172
+ return packageName;
114
173
  };
115
174
  const generateAppsScriptTypes = async ({
116
175
  project: projectPath,
@@ -127,8 +186,12 @@ const generateAppsScriptTypes = async ({
127
186
  consola.consola.info("Starting AppsScript type generation with gasnuki...");
128
187
  consola.consola.info(` AppsScript Source Directory: ${absoluteSrcDir}`);
129
188
  consola.consola.info(` Output File: ${absoluteOutputFile}`);
189
+ let tsConfigFilePath = path__namespace.resolve(projectPath, "tsconfig.json");
190
+ if (fs__namespace.existsSync(path__namespace.resolve(projectPath, "tsconfig.app.json"))) {
191
+ tsConfigFilePath = path__namespace.resolve(projectPath, "tsconfig.app.json");
192
+ }
130
193
  const project = projectInstance ?? new tsMorph.Project({
131
- tsConfigFilePath: path__namespace.resolve(projectPath, "tsconfig.json"),
194
+ tsConfigFilePath,
132
195
  skipAddingFilesFromTsConfig: true
133
196
  });
134
197
  const sourceFilesPattern = path__namespace.join(absoluteSrcDir, "**/*.ts").replace(/\\/g, "/");
@@ -425,7 +488,7 @@ const generateAppsScriptTypes = async ({
425
488
  if (!functionSignatureSymbols.has(symbol)) {
426
489
  continue;
427
490
  }
428
- const packageName = getPackageNameFromNodeModulesPath_(sourceFilePath);
491
+ const packageName = resolveNodeModuleSpecifier_(sourceFilePath);
429
492
  if (packageName) {
430
493
  processedSymbols.add(symbolName);
431
494
  if (!importsMap.has(packageName)) {
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.Co0-wxJi.cjs');
5
+ const config = require('./shared/gasnuki.Clw_jH65.cjs');
6
6
  require('node:crypto');
7
7
  require('node:fs');
8
8
  require('ts-morph');
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.DePJgSg9.mjs';
3
+ import { l as loadConfig, g as generateAppsScriptTypes } from './shared/gasnuki.CYbD-wKI.mjs';
4
4
  import 'node:crypto';
5
5
  import 'node:fs';
6
6
  import 'ts-morph';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ciderjs/gasnuki",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
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",
@@ -68,7 +68,7 @@
68
68
  },
69
69
  "devDependencies": {
70
70
  "@biomejs/biome": "^2.3.11",
71
- "@types/node": "^25.0.5",
71
+ "@types/node": "^25.0.6",
72
72
  "@vitest/coverage-v8": "4.0.16",
73
73
  "typescript": "^5.9.3",
74
74
  "unbuild": "^3.6.1",