@ciderjs/gasnuki 0.4.0 → 0.4.1
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 +1 -1
- package/README.md +1 -1
- package/dist/cli.cjs +2 -2
- package/dist/cli.mjs +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +2 -2
- package/dist/shared/{gasnuki.DfLTmLhN.cjs → gasnuki.Co0-wxJi.cjs} +142 -41
- package/dist/shared/{gasnuki.SJQVcSIQ.mjs → gasnuki.DePJgSg9.mjs} +142 -41
- package/dist/vite.cjs +1 -1
- package/dist/vite.mjs +1 -1
- package/package.json +1 -1
package/README.ja.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @ciderjs/gasnuki
|
|
2
2
|
|
|
3
3
|
[](./README.md)
|
|
4
|
-
[](https://github.com/luthpg/gasnuki)
|
|
5
5
|
[](LICENSE)
|
|
6
6
|
[](https://www.npmjs.com/package/@ciderjs/gasnuki)
|
|
7
7
|
[](https://github.com/luthpg/gasnuki/issues)
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @ciderjs/gasnuki
|
|
2
2
|
|
|
3
3
|
[](./README.ja.md)
|
|
4
|
-
[](https://github.com/luthpg/gasnuki)
|
|
5
5
|
[](LICENSE)
|
|
6
6
|
[](https://www.npmjs.com/package/@ciderjs/gasnuki)
|
|
7
7
|
[](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.
|
|
7
|
+
const config = require('./shared/gasnuki.Co0-wxJi.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.4.
|
|
29
|
+
const version = "0.4.1";
|
|
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.
|
|
5
|
+
import { l as loadConfig } from './shared/gasnuki.DePJgSg9.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.4.
|
|
13
|
+
const version = "0.4.1";
|
|
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.
|
|
6
|
+
const config = require('./shared/gasnuki.Co0-wxJi.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.
|
|
5
|
-
export { d as defineConfig } from './shared/gasnuki.
|
|
4
|
+
import { g as generateAppsScriptTypes } from './shared/gasnuki.DePJgSg9.mjs';
|
|
5
|
+
export { d as defineConfig } from './shared/gasnuki.DePJgSg9.mjs';
|
|
6
6
|
import 'node:crypto';
|
|
7
7
|
import 'node:fs';
|
|
8
8
|
import 'ts-morph';
|
|
@@ -72,7 +72,7 @@ const getInterfaceMethodDefinition_ = (name, node) => {
|
|
|
72
72
|
`;
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
const cleanType = (t) => t.replace(/import\(
|
|
75
|
+
const cleanType = (t) => t.replace(/import\(".*?"\)\.default\./g, "").replace(/import\(".*?"\)\./g, "");
|
|
76
76
|
const cleanedReturnType = cleanType(returnType);
|
|
77
77
|
const cleanedParameters = parameters.replace(
|
|
78
78
|
/:\s*([^,;)]+)/g,
|
|
@@ -189,8 +189,85 @@ const generateAppsScriptTypes = async ({
|
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
|
-
const collectSymbolsFromType = (type, foundSymbols) => {
|
|
192
|
+
const collectSymbolsFromType = (type, foundSymbols, contextNode, depth = 0, isComponent = false) => {
|
|
193
|
+
if (type.isArray()) {
|
|
194
|
+
const elementType = type.getArrayElementType();
|
|
195
|
+
if (elementType) {
|
|
196
|
+
collectSymbolsFromType(
|
|
197
|
+
elementType,
|
|
198
|
+
foundSymbols,
|
|
199
|
+
contextNode,
|
|
200
|
+
depth + 1
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (type.isTuple()) {
|
|
205
|
+
for (const element of type.getTupleElements()) {
|
|
206
|
+
collectSymbolsFromType(element, foundSymbols, contextNode, depth + 1);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
for (const typeArg of type.getTypeArguments()) {
|
|
210
|
+
collectSymbolsFromType(typeArg, foundSymbols, contextNode, depth + 1);
|
|
211
|
+
}
|
|
212
|
+
for (const typeArg of type.getAliasTypeArguments()) {
|
|
213
|
+
collectSymbolsFromType(typeArg, foundSymbols, contextNode, depth + 1);
|
|
214
|
+
}
|
|
215
|
+
if (type.isUnion()) {
|
|
216
|
+
for (const unionType of type.getUnionTypes()) {
|
|
217
|
+
collectSymbolsFromType(
|
|
218
|
+
unionType,
|
|
219
|
+
foundSymbols,
|
|
220
|
+
contextNode,
|
|
221
|
+
depth + 1,
|
|
222
|
+
true
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (type.isIntersection()) {
|
|
227
|
+
for (const intersectionType of type.getIntersectionTypes()) {
|
|
228
|
+
collectSymbolsFromType(
|
|
229
|
+
intersectionType,
|
|
230
|
+
foundSymbols,
|
|
231
|
+
contextNode,
|
|
232
|
+
depth + 1,
|
|
233
|
+
true
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
const typeText = type.getText(contextNode);
|
|
238
|
+
const importMatches = typeText.matchAll(
|
|
239
|
+
/import\("(.*?)"\)\.([^<>[\]{}() ,;]+)/g
|
|
240
|
+
);
|
|
241
|
+
for (const match of importMatches) {
|
|
242
|
+
const absolutePath = match[1];
|
|
243
|
+
const typeName = match[2];
|
|
244
|
+
if (typeName === "default" || typeName === "__type") continue;
|
|
245
|
+
let sourceFile = project.getSourceFile(absolutePath) || project.addSourceFileAtPathIfExists(absolutePath);
|
|
246
|
+
if (!sourceFile) {
|
|
247
|
+
const extensions = [".ts", ".d.ts", ".tsx"];
|
|
248
|
+
for (const ext of extensions) {
|
|
249
|
+
sourceFile = project.getSourceFile(absolutePath + ext) || project.addSourceFileAtPathIfExists(absolutePath + ext);
|
|
250
|
+
if (sourceFile) break;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (sourceFile) {
|
|
254
|
+
const exported = sourceFile.getExportedDeclarations().get(typeName);
|
|
255
|
+
let s;
|
|
256
|
+
if (exported && exported.length > 0) {
|
|
257
|
+
s = exported[0].getSymbol();
|
|
258
|
+
} else {
|
|
259
|
+
s = sourceFile.getInterface(typeName)?.getSymbol() || sourceFile.getTypeAlias(typeName)?.getSymbol() || sourceFile.getEnum(typeName)?.getSymbol() || sourceFile.getClass(typeName)?.getSymbol();
|
|
260
|
+
}
|
|
261
|
+
if (s && !foundSymbols.has(s)) {
|
|
262
|
+
foundSymbols.add(s);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
193
266
|
const aliasSymbol = type.getAliasSymbol();
|
|
267
|
+
let symbol = type.getSymbol();
|
|
268
|
+
if (!symbol && !aliasSymbol) {
|
|
269
|
+
symbol = type.getApparentType().getSymbol();
|
|
270
|
+
}
|
|
194
271
|
if (aliasSymbol) {
|
|
195
272
|
if (foundSymbols.has(aliasSymbol)) {
|
|
196
273
|
return;
|
|
@@ -201,14 +278,10 @@ const generateAppsScriptTypes = async ({
|
|
|
201
278
|
const isExternal = sourceFilePath.includes("node_modules") || !sourceFilePath.replace(/\\/g, "/").startsWith(absoluteSrcDir.replace(/\\/g, "/")) && !sourceFilePath.replace(/\\/g, "/").startsWith(path__namespace.join(projectPath, srcDir).replace(/\\/g, "/"));
|
|
202
279
|
if (isExternal) {
|
|
203
280
|
foundSymbols.add(aliasSymbol);
|
|
204
|
-
for (const typeArg of type.getAliasTypeArguments()) {
|
|
205
|
-
collectSymbolsFromType(typeArg, foundSymbols);
|
|
206
|
-
}
|
|
207
281
|
return;
|
|
208
282
|
}
|
|
209
283
|
}
|
|
210
284
|
}
|
|
211
|
-
const symbol = type.getSymbol();
|
|
212
285
|
let shouldTraverseProperties = true;
|
|
213
286
|
if (symbol) {
|
|
214
287
|
if (foundSymbols.has(symbol)) {
|
|
@@ -222,42 +295,68 @@ const generateAppsScriptTypes = async ({
|
|
|
222
295
|
path__namespace.join(projectPath, srcDir).replace(/\\/g, "/")
|
|
223
296
|
);
|
|
224
297
|
if (isExternal) {
|
|
225
|
-
|
|
298
|
+
const isAnonymous = declarations.every(
|
|
299
|
+
(d) => d.getKind() === tsMorph.SyntaxKind.TypeLiteral || d.getKind() === tsMorph.SyntaxKind.ObjectLiteralExpression
|
|
300
|
+
);
|
|
301
|
+
if (!isComponent && !isAnonymous) {
|
|
302
|
+
shouldTraverseProperties = false;
|
|
303
|
+
}
|
|
226
304
|
}
|
|
227
305
|
}
|
|
228
306
|
}
|
|
229
307
|
}
|
|
230
|
-
if (shouldTraverseProperties
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
308
|
+
if (shouldTraverseProperties) {
|
|
309
|
+
const props = /* @__PURE__ */ new Set([
|
|
310
|
+
...type.getProperties(),
|
|
311
|
+
...type.getApparentProperties()
|
|
312
|
+
]);
|
|
313
|
+
for (const prop of props) {
|
|
314
|
+
let propType;
|
|
315
|
+
if (contextNode) {
|
|
316
|
+
try {
|
|
317
|
+
propType = prop.getTypeAtLocation(contextNode);
|
|
318
|
+
} catch {
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (!propType || propType.getText() === "any") {
|
|
322
|
+
const propDecls = prop.getDeclarations();
|
|
323
|
+
if (propDecls.length > 0) {
|
|
324
|
+
propType = propDecls[0].getType();
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
if ((!propType || propType.getText() === "any") && prop.getAliasedSymbol()) {
|
|
328
|
+
const aliased = prop.getAliasedSymbol();
|
|
329
|
+
if (aliased) {
|
|
330
|
+
const decl = aliased.getValueDeclaration() || aliased.getDeclarations()[0];
|
|
331
|
+
if (decl) {
|
|
332
|
+
propType = decl.getType();
|
|
244
333
|
}
|
|
245
334
|
}
|
|
246
|
-
collectSymbolsFromType(propDecl.getType(), foundSymbols);
|
|
247
335
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
336
|
+
if (propType) {
|
|
337
|
+
const propDecls = prop.getDeclarations();
|
|
338
|
+
if (propDecls.length > 0) {
|
|
339
|
+
const propDecl = propDecls[0];
|
|
340
|
+
const compilerNode = propDecl.compilerNode;
|
|
341
|
+
if (
|
|
342
|
+
// @ts-expect-error - checking kind directly for perf
|
|
343
|
+
compilerNode.name && // @ts-expect-error - checking kind directly for perf
|
|
344
|
+
compilerNode.name.kind === tsMorph.SyntaxKind.ComputedPropertyName
|
|
345
|
+
) {
|
|
346
|
+
const expression = propDecl.getNameNode().getExpression();
|
|
347
|
+
const s = expression.getSymbol();
|
|
348
|
+
if (s && !foundSymbols.has(s)) {
|
|
349
|
+
foundSymbols.add(s);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
collectSymbolsFromType(
|
|
354
|
+
propType,
|
|
355
|
+
foundSymbols,
|
|
356
|
+
contextNode,
|
|
357
|
+
depth + 1
|
|
358
|
+
);
|
|
359
|
+
}
|
|
261
360
|
}
|
|
262
361
|
}
|
|
263
362
|
};
|
|
@@ -268,14 +367,14 @@ const generateAppsScriptTypes = async ({
|
|
|
268
367
|
const func = decl.getKind() === tsMorph.SyntaxKind.FunctionDeclaration ? decl : decl.getInitializer();
|
|
269
368
|
const parameters = func.getParameters();
|
|
270
369
|
for (const param of parameters) {
|
|
271
|
-
collectSymbolsFromType(param.getType(), functionSignatureSymbols);
|
|
272
|
-
collectSymbolsFromType(param.getType(), symbolsToProcess);
|
|
370
|
+
collectSymbolsFromType(param.getType(), functionSignatureSymbols, func);
|
|
371
|
+
collectSymbolsFromType(param.getType(), symbolsToProcess, func);
|
|
273
372
|
}
|
|
274
373
|
const returnType = func.getReturnType();
|
|
275
|
-
collectSymbolsFromType(returnType, functionSignatureSymbols);
|
|
276
|
-
collectSymbolsFromType(returnType, symbolsToProcess);
|
|
374
|
+
collectSymbolsFromType(returnType, functionSignatureSymbols, func);
|
|
375
|
+
collectSymbolsFromType(returnType, symbolsToProcess, func);
|
|
277
376
|
} else if (decl.getKind() === tsMorph.SyntaxKind.InterfaceDeclaration || decl.getKind() === tsMorph.SyntaxKind.TypeAliasDeclaration) {
|
|
278
|
-
collectSymbolsFromType(decl.getType(), symbolsToProcess);
|
|
377
|
+
collectSymbolsFromType(decl.getType(), symbolsToProcess, decl);
|
|
279
378
|
}
|
|
280
379
|
}
|
|
281
380
|
const importsMap = /* @__PURE__ */ new Map();
|
|
@@ -424,7 +523,9 @@ ${text}`;
|
|
|
424
523
|
if (sortedModulePaths.length > 0) {
|
|
425
524
|
const importStatements = sortedModulePaths.map((modulePath) => {
|
|
426
525
|
const imports = [...importsMap.get(modulePath) ?? []].sort().filter((importName) => {
|
|
427
|
-
const regex = new RegExp(
|
|
526
|
+
const regex = new RegExp(
|
|
527
|
+
`(?:import\\(".*?"\\)\\.|\\b)${importName}\\b`
|
|
528
|
+
);
|
|
428
529
|
return regex.test(bodyContent);
|
|
429
530
|
});
|
|
430
531
|
if (imports.length === 0) {
|
|
@@ -54,7 +54,7 @@ const getInterfaceMethodDefinition_ = (name, node) => {
|
|
|
54
54
|
`;
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
const cleanType = (t) => t.replace(/import\(
|
|
57
|
+
const cleanType = (t) => t.replace(/import\(".*?"\)\.default\./g, "").replace(/import\(".*?"\)\./g, "");
|
|
58
58
|
const cleanedReturnType = cleanType(returnType);
|
|
59
59
|
const cleanedParameters = parameters.replace(
|
|
60
60
|
/:\s*([^,;)]+)/g,
|
|
@@ -171,8 +171,85 @@ const generateAppsScriptTypes = async ({
|
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
-
const collectSymbolsFromType = (type, foundSymbols) => {
|
|
174
|
+
const collectSymbolsFromType = (type, foundSymbols, contextNode, depth = 0, isComponent = false) => {
|
|
175
|
+
if (type.isArray()) {
|
|
176
|
+
const elementType = type.getArrayElementType();
|
|
177
|
+
if (elementType) {
|
|
178
|
+
collectSymbolsFromType(
|
|
179
|
+
elementType,
|
|
180
|
+
foundSymbols,
|
|
181
|
+
contextNode,
|
|
182
|
+
depth + 1
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (type.isTuple()) {
|
|
187
|
+
for (const element of type.getTupleElements()) {
|
|
188
|
+
collectSymbolsFromType(element, foundSymbols, contextNode, depth + 1);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
for (const typeArg of type.getTypeArguments()) {
|
|
192
|
+
collectSymbolsFromType(typeArg, foundSymbols, contextNode, depth + 1);
|
|
193
|
+
}
|
|
194
|
+
for (const typeArg of type.getAliasTypeArguments()) {
|
|
195
|
+
collectSymbolsFromType(typeArg, foundSymbols, contextNode, depth + 1);
|
|
196
|
+
}
|
|
197
|
+
if (type.isUnion()) {
|
|
198
|
+
for (const unionType of type.getUnionTypes()) {
|
|
199
|
+
collectSymbolsFromType(
|
|
200
|
+
unionType,
|
|
201
|
+
foundSymbols,
|
|
202
|
+
contextNode,
|
|
203
|
+
depth + 1,
|
|
204
|
+
true
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (type.isIntersection()) {
|
|
209
|
+
for (const intersectionType of type.getIntersectionTypes()) {
|
|
210
|
+
collectSymbolsFromType(
|
|
211
|
+
intersectionType,
|
|
212
|
+
foundSymbols,
|
|
213
|
+
contextNode,
|
|
214
|
+
depth + 1,
|
|
215
|
+
true
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const typeText = type.getText(contextNode);
|
|
220
|
+
const importMatches = typeText.matchAll(
|
|
221
|
+
/import\("(.*?)"\)\.([^<>[\]{}() ,;]+)/g
|
|
222
|
+
);
|
|
223
|
+
for (const match of importMatches) {
|
|
224
|
+
const absolutePath = match[1];
|
|
225
|
+
const typeName = match[2];
|
|
226
|
+
if (typeName === "default" || typeName === "__type") continue;
|
|
227
|
+
let sourceFile = project.getSourceFile(absolutePath) || project.addSourceFileAtPathIfExists(absolutePath);
|
|
228
|
+
if (!sourceFile) {
|
|
229
|
+
const extensions = [".ts", ".d.ts", ".tsx"];
|
|
230
|
+
for (const ext of extensions) {
|
|
231
|
+
sourceFile = project.getSourceFile(absolutePath + ext) || project.addSourceFileAtPathIfExists(absolutePath + ext);
|
|
232
|
+
if (sourceFile) break;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (sourceFile) {
|
|
236
|
+
const exported = sourceFile.getExportedDeclarations().get(typeName);
|
|
237
|
+
let s;
|
|
238
|
+
if (exported && exported.length > 0) {
|
|
239
|
+
s = exported[0].getSymbol();
|
|
240
|
+
} else {
|
|
241
|
+
s = sourceFile.getInterface(typeName)?.getSymbol() || sourceFile.getTypeAlias(typeName)?.getSymbol() || sourceFile.getEnum(typeName)?.getSymbol() || sourceFile.getClass(typeName)?.getSymbol();
|
|
242
|
+
}
|
|
243
|
+
if (s && !foundSymbols.has(s)) {
|
|
244
|
+
foundSymbols.add(s);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
175
248
|
const aliasSymbol = type.getAliasSymbol();
|
|
249
|
+
let symbol = type.getSymbol();
|
|
250
|
+
if (!symbol && !aliasSymbol) {
|
|
251
|
+
symbol = type.getApparentType().getSymbol();
|
|
252
|
+
}
|
|
176
253
|
if (aliasSymbol) {
|
|
177
254
|
if (foundSymbols.has(aliasSymbol)) {
|
|
178
255
|
return;
|
|
@@ -183,14 +260,10 @@ const generateAppsScriptTypes = async ({
|
|
|
183
260
|
const isExternal = sourceFilePath.includes("node_modules") || !sourceFilePath.replace(/\\/g, "/").startsWith(absoluteSrcDir.replace(/\\/g, "/")) && !sourceFilePath.replace(/\\/g, "/").startsWith(path.join(projectPath, srcDir).replace(/\\/g, "/"));
|
|
184
261
|
if (isExternal) {
|
|
185
262
|
foundSymbols.add(aliasSymbol);
|
|
186
|
-
for (const typeArg of type.getAliasTypeArguments()) {
|
|
187
|
-
collectSymbolsFromType(typeArg, foundSymbols);
|
|
188
|
-
}
|
|
189
263
|
return;
|
|
190
264
|
}
|
|
191
265
|
}
|
|
192
266
|
}
|
|
193
|
-
const symbol = type.getSymbol();
|
|
194
267
|
let shouldTraverseProperties = true;
|
|
195
268
|
if (symbol) {
|
|
196
269
|
if (foundSymbols.has(symbol)) {
|
|
@@ -204,42 +277,68 @@ const generateAppsScriptTypes = async ({
|
|
|
204
277
|
path.join(projectPath, srcDir).replace(/\\/g, "/")
|
|
205
278
|
);
|
|
206
279
|
if (isExternal) {
|
|
207
|
-
|
|
280
|
+
const isAnonymous = declarations.every(
|
|
281
|
+
(d) => d.getKind() === SyntaxKind.TypeLiteral || d.getKind() === SyntaxKind.ObjectLiteralExpression
|
|
282
|
+
);
|
|
283
|
+
if (!isComponent && !isAnonymous) {
|
|
284
|
+
shouldTraverseProperties = false;
|
|
285
|
+
}
|
|
208
286
|
}
|
|
209
287
|
}
|
|
210
288
|
}
|
|
211
289
|
}
|
|
212
|
-
if (shouldTraverseProperties
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
290
|
+
if (shouldTraverseProperties) {
|
|
291
|
+
const props = /* @__PURE__ */ new Set([
|
|
292
|
+
...type.getProperties(),
|
|
293
|
+
...type.getApparentProperties()
|
|
294
|
+
]);
|
|
295
|
+
for (const prop of props) {
|
|
296
|
+
let propType;
|
|
297
|
+
if (contextNode) {
|
|
298
|
+
try {
|
|
299
|
+
propType = prop.getTypeAtLocation(contextNode);
|
|
300
|
+
} catch {
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (!propType || propType.getText() === "any") {
|
|
304
|
+
const propDecls = prop.getDeclarations();
|
|
305
|
+
if (propDecls.length > 0) {
|
|
306
|
+
propType = propDecls[0].getType();
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if ((!propType || propType.getText() === "any") && prop.getAliasedSymbol()) {
|
|
310
|
+
const aliased = prop.getAliasedSymbol();
|
|
311
|
+
if (aliased) {
|
|
312
|
+
const decl = aliased.getValueDeclaration() || aliased.getDeclarations()[0];
|
|
313
|
+
if (decl) {
|
|
314
|
+
propType = decl.getType();
|
|
226
315
|
}
|
|
227
316
|
}
|
|
228
|
-
collectSymbolsFromType(propDecl.getType(), foundSymbols);
|
|
229
317
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
318
|
+
if (propType) {
|
|
319
|
+
const propDecls = prop.getDeclarations();
|
|
320
|
+
if (propDecls.length > 0) {
|
|
321
|
+
const propDecl = propDecls[0];
|
|
322
|
+
const compilerNode = propDecl.compilerNode;
|
|
323
|
+
if (
|
|
324
|
+
// @ts-expect-error - checking kind directly for perf
|
|
325
|
+
compilerNode.name && // @ts-expect-error - checking kind directly for perf
|
|
326
|
+
compilerNode.name.kind === SyntaxKind.ComputedPropertyName
|
|
327
|
+
) {
|
|
328
|
+
const expression = propDecl.getNameNode().getExpression();
|
|
329
|
+
const s = expression.getSymbol();
|
|
330
|
+
if (s && !foundSymbols.has(s)) {
|
|
331
|
+
foundSymbols.add(s);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
collectSymbolsFromType(
|
|
336
|
+
propType,
|
|
337
|
+
foundSymbols,
|
|
338
|
+
contextNode,
|
|
339
|
+
depth + 1
|
|
340
|
+
);
|
|
341
|
+
}
|
|
243
342
|
}
|
|
244
343
|
}
|
|
245
344
|
};
|
|
@@ -250,14 +349,14 @@ const generateAppsScriptTypes = async ({
|
|
|
250
349
|
const func = decl.getKind() === SyntaxKind.FunctionDeclaration ? decl : decl.getInitializer();
|
|
251
350
|
const parameters = func.getParameters();
|
|
252
351
|
for (const param of parameters) {
|
|
253
|
-
collectSymbolsFromType(param.getType(), functionSignatureSymbols);
|
|
254
|
-
collectSymbolsFromType(param.getType(), symbolsToProcess);
|
|
352
|
+
collectSymbolsFromType(param.getType(), functionSignatureSymbols, func);
|
|
353
|
+
collectSymbolsFromType(param.getType(), symbolsToProcess, func);
|
|
255
354
|
}
|
|
256
355
|
const returnType = func.getReturnType();
|
|
257
|
-
collectSymbolsFromType(returnType, functionSignatureSymbols);
|
|
258
|
-
collectSymbolsFromType(returnType, symbolsToProcess);
|
|
356
|
+
collectSymbolsFromType(returnType, functionSignatureSymbols, func);
|
|
357
|
+
collectSymbolsFromType(returnType, symbolsToProcess, func);
|
|
259
358
|
} else if (decl.getKind() === SyntaxKind.InterfaceDeclaration || decl.getKind() === SyntaxKind.TypeAliasDeclaration) {
|
|
260
|
-
collectSymbolsFromType(decl.getType(), symbolsToProcess);
|
|
359
|
+
collectSymbolsFromType(decl.getType(), symbolsToProcess, decl);
|
|
261
360
|
}
|
|
262
361
|
}
|
|
263
362
|
const importsMap = /* @__PURE__ */ new Map();
|
|
@@ -406,7 +505,9 @@ ${text}`;
|
|
|
406
505
|
if (sortedModulePaths.length > 0) {
|
|
407
506
|
const importStatements = sortedModulePaths.map((modulePath) => {
|
|
408
507
|
const imports = [...importsMap.get(modulePath) ?? []].sort().filter((importName) => {
|
|
409
|
-
const regex = new RegExp(
|
|
508
|
+
const regex = new RegExp(
|
|
509
|
+
`(?:import\\(".*?"\\)\\.|\\b)${importName}\\b`
|
|
510
|
+
);
|
|
410
511
|
return regex.test(bodyContent);
|
|
411
512
|
});
|
|
412
513
|
if (imports.length === 0) {
|
package/dist/vite.cjs
CHANGED
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.
|
|
3
|
+
import { l as loadConfig, g as generateAppsScriptTypes } from './shared/gasnuki.DePJgSg9.mjs';
|
|
4
4
|
import 'node:crypto';
|
|
5
5
|
import 'node:fs';
|
|
6
6
|
import 'ts-morph';
|