@arcgis/core-adapter 4.32.0-next.50 → 4.32.0-next.51
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/package.json +4 -1
- package/.turbo/turbo-build.log +0 -16
- package/scripts/generator.ts +0 -451
- package/scripts/update-adapter-typings.ts +0 -105
- package/src/index.ts +0 -11848
- package/support/api-reference-esm-imports.json +0 -982
- package/support/arcgis.d.ts +0 -140407
- package/support/publicModules.ts +0 -26
- package/tsconfig.json +0 -5
- package/tsup.config.ts +0 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcgis/core-adapter",
|
|
3
|
-
"version": "4.32.0-next.
|
|
3
|
+
"version": "4.32.0-next.51",
|
|
4
4
|
"description": "ArcGIS Core Adapter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
"require": "./dist/index.cjs"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist/"
|
|
18
|
+
],
|
|
16
19
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
17
20
|
"dependencies": {
|
|
18
21
|
"tslib": "^2.7.0"
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
CLI Building entry: src/index.ts
|
|
2
|
-
CLI Using tsconfig: tsconfig.json
|
|
3
|
-
CLI tsup v8.3.5
|
|
4
|
-
CLI Using tsup config: /data/arcgis-web-compoments/actions-runner-1/_work/arcgis-web-components/arcgis-web-components/packages/support-packages/core-adapter/tsup.config.ts
|
|
5
|
-
CLI Target: es2020
|
|
6
|
-
CLI Cleaning output folder
|
|
7
|
-
ESM Build start
|
|
8
|
-
CJS Build start
|
|
9
|
-
CJS dist/index.cjs 626.78 KB
|
|
10
|
-
CJS ⚡️ Build success in 2533ms
|
|
11
|
-
ESM dist/index.js 484.95 KB
|
|
12
|
-
ESM ⚡️ Build success in 2717ms
|
|
13
|
-
DTS Build start
|
|
14
|
-
DTS ⚡️ Build success in 25489ms
|
|
15
|
-
DTS dist/index.d.ts 254.37 KB
|
|
16
|
-
DTS dist/index.d.cts 254.37 KB
|
package/scripts/generator.ts
DELETED
|
@@ -1,451 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import resolvePkg from "resolve-pkg";
|
|
4
|
-
import type { SourceFile } from "ts-morph";
|
|
5
|
-
import { Project } from "ts-morph";
|
|
6
|
-
import ts from "typescript";
|
|
7
|
-
import { publicModules } from "../support/publicModules";
|
|
8
|
-
|
|
9
|
-
const dirname = import.meta.dirname;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Collect the details of a type we are interested in
|
|
13
|
-
*/
|
|
14
|
-
interface TypeInfo {
|
|
15
|
-
// The path of the module that contains the type. For example: `esri/identity/IdentityManager`
|
|
16
|
-
amdModulePath: string;
|
|
17
|
-
// The path of the module that contains the type. For example: `@arcgis/core/identity/IdentityManager`
|
|
18
|
-
esmModulePath?: string;
|
|
19
|
-
// The name of the type. For example: `__esri.Credential`
|
|
20
|
-
typeName: string;
|
|
21
|
-
// If the type is a class and has at least one constructor, we collect the parameters of the constructor
|
|
22
|
-
constructorParameters?: ParameterInfo[];
|
|
23
|
-
// If the type is a singleton then instanceType will be true
|
|
24
|
-
instanceType?: boolean;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Describe a parameter of a constructor
|
|
29
|
-
*/
|
|
30
|
-
interface ParameterInfo {
|
|
31
|
-
// The name of the parameter
|
|
32
|
-
name: string;
|
|
33
|
-
// The type of the parameter
|
|
34
|
-
type: string;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const nativeTypes: string[] = [
|
|
38
|
-
"number",
|
|
39
|
-
"string",
|
|
40
|
-
"boolean",
|
|
41
|
-
"null",
|
|
42
|
-
"undefined",
|
|
43
|
-
"object",
|
|
44
|
-
"symbol",
|
|
45
|
-
"any",
|
|
46
|
-
"void",
|
|
47
|
-
"never",
|
|
48
|
-
"array",
|
|
49
|
-
];
|
|
50
|
-
|
|
51
|
-
const nativeArrayTypes = nativeTypes.map((x) => `${x}[]`);
|
|
52
|
-
const nativeGenericTypes = nativeTypes.map((x) => `<${x}>`);
|
|
53
|
-
|
|
54
|
-
// Modules to ignore
|
|
55
|
-
const ignoreExports: string[] = [
|
|
56
|
-
// virtual
|
|
57
|
-
"esri/core/units",
|
|
58
|
-
"esri/core/quantity",
|
|
59
|
-
];
|
|
60
|
-
|
|
61
|
-
// Module that returns an instance of a class
|
|
62
|
-
const singletons = new Map<string, string>([["esri/identity/IdentityManager", "__esri.IdentityManager"]]);
|
|
63
|
-
|
|
64
|
-
// The header of the index file
|
|
65
|
-
// We want to detect if the environment is AMD
|
|
66
|
-
// Define the AMD import module global
|
|
67
|
-
const indexHeader = `
|
|
68
|
-
const isAMD = typeof window !== "undefined" && "$arcgis" in window && typeof window.$arcgis === "object" && "import" in window.$arcgis && !("forceESM" in window.$arcgis);
|
|
69
|
-
|
|
70
|
-
declare global {
|
|
71
|
-
interface Window {
|
|
72
|
-
$arcgis: { import: <T>(modules: string | string[], forceESM?: boolean) => Promise<T> };
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
interface DefaultModule<T> {
|
|
77
|
-
default: T;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
function isDefaultModule<T>(module: DefaultModule<T> | T): module is DefaultModule<T> {
|
|
82
|
-
return (module as DefaultModule<T>).default !== undefined;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Load an undocumented module respecting the current environment (AMD or ESM).
|
|
87
|
-
* The module type will certainly be \`any\` as it is not documented.
|
|
88
|
-
* For ESM, if the module exports a default, it will be returned, otherwise the module itself will be returned.
|
|
89
|
-
* @param modulePath - The path to the module to load, example: "@arcgis/core/Map"
|
|
90
|
-
* @param deferredImport - A function that should call import() and return the module, example: () => import("@arcgis/core/Map")
|
|
91
|
-
* @returns - Promise that resolves to the module
|
|
92
|
-
*/
|
|
93
|
-
export async function loadUndocumentedModule<T>(modulePath: string, deferredImport: () => Promise<T>): Promise<T> {
|
|
94
|
-
if (isAMD) {
|
|
95
|
-
return await window.$arcgis.import(modulePath);
|
|
96
|
-
}
|
|
97
|
-
const module = deferredImport();
|
|
98
|
-
return isDefaultModule(module) ? module.default : module;
|
|
99
|
-
}
|
|
100
|
-
`;
|
|
101
|
-
|
|
102
|
-
class PublicTypeValidator {
|
|
103
|
-
project: Project;
|
|
104
|
-
source: SourceFile | undefined;
|
|
105
|
-
|
|
106
|
-
constructor() {
|
|
107
|
-
this.project = new Project();
|
|
108
|
-
const coreInterfacesPath = resolvePkg("@arcgis/core/interfaces.d.ts");
|
|
109
|
-
if (!coreInterfacesPath) {
|
|
110
|
-
console.error("Could not find @arcgis/core/interfaces.d.ts. Make sure you have installed @arcgis/core.");
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
this.source = this.project.addSourceFileAtPath(coreInterfacesPath);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
validateType(typeName: string): boolean {
|
|
118
|
-
if (!this.source) {
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const [namespaceName, name] = typeName.split(".");
|
|
123
|
-
const namespace = this.source.getModule(namespaceName);
|
|
124
|
-
if (!namespace) {
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// Under the namespace `__esri`, we can find type as class, interface or namespace
|
|
129
|
-
// ```
|
|
130
|
-
// declare namespace __esri {
|
|
131
|
-
// export interface Credential { ... }
|
|
132
|
-
// export class Credential { ... }
|
|
133
|
-
// namespace geometry { ... }
|
|
134
|
-
// }
|
|
135
|
-
// ```
|
|
136
|
-
return !!namespace.getClass(name) || !!namespace.getInterface(name) || !!namespace.getModule(name);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function generate(): void {
|
|
141
|
-
console.log("Reading typings file...");
|
|
142
|
-
|
|
143
|
-
// Load our esm import references
|
|
144
|
-
const esmImportReferencesContent: string = fs.readFileSync(
|
|
145
|
-
path.join(dirname, "../support/api-reference-esm-imports.json"),
|
|
146
|
-
"utf8",
|
|
147
|
-
);
|
|
148
|
-
const amdImportReferences = JSON.parse(esmImportReferencesContent) as Record<string, string>;
|
|
149
|
-
const amdImportReferencesKeys = Object.keys(amdImportReferences);
|
|
150
|
-
|
|
151
|
-
// Start building the index file
|
|
152
|
-
// At the top we add the amd logic
|
|
153
|
-
const indexFileStatements: string[] = [];
|
|
154
|
-
indexFileStatements.push(indexHeader);
|
|
155
|
-
|
|
156
|
-
// Create a ts program with the typings file
|
|
157
|
-
// Also create a type checker
|
|
158
|
-
const typingsFilepath = path.resolve(dirname, "../support/arcgis.d.ts");
|
|
159
|
-
const program = ts.createProgram([typingsFilepath], {});
|
|
160
|
-
const checker = program.getTypeChecker();
|
|
161
|
-
const typingsProgram = program.getSourceFile(typingsFilepath);
|
|
162
|
-
if (!typingsProgram) {
|
|
163
|
-
console.error(`Could not find source file: ${typingsFilepath}`);
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const publicTypeValidator = new PublicTypeValidator();
|
|
168
|
-
|
|
169
|
-
const visitedModules = new Set<string>();
|
|
170
|
-
|
|
171
|
-
// We will visit the typings and extract the symbols we need
|
|
172
|
-
// Add the singletons to the typeInfos array
|
|
173
|
-
const typeInfos: TypeInfo[] = [...singletons.entries()].map(([amdModulePath, typeName]) => ({
|
|
174
|
-
amdModulePath,
|
|
175
|
-
esmModulePath: convertAmdToEsmPath(amdModulePath),
|
|
176
|
-
typeName,
|
|
177
|
-
instanceType: true,
|
|
178
|
-
}));
|
|
179
|
-
|
|
180
|
-
/** Create a visitor function for the context */
|
|
181
|
-
function createVisitor(context: ts.TransformationContext): ts.Visitor<ts.Node, ts.Node> {
|
|
182
|
-
return function visit(node: ts.Node): ts.Node {
|
|
183
|
-
// Visit each child node
|
|
184
|
-
node = ts.visitEachChild(node, visit, context);
|
|
185
|
-
|
|
186
|
-
// We are only interested in module declarations
|
|
187
|
-
// Example: `declare module "esri/identity/IdentityManager" {`
|
|
188
|
-
if (!ts.isModuleDeclaration(node)) {
|
|
189
|
-
return node;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// Only include imports that are in the import dictionary
|
|
193
|
-
// or are part of "esri/applications" modules
|
|
194
|
-
const amdModulePath = node.name.text;
|
|
195
|
-
if (visitedModules.has(amdModulePath)) {
|
|
196
|
-
console.log("\x1b[33m", "WARNING: Skipping duplicate module: ", amdModulePath);
|
|
197
|
-
return node;
|
|
198
|
-
}
|
|
199
|
-
visitedModules.add(amdModulePath);
|
|
200
|
-
if (!amdImportReferencesKeys.includes(amdModulePath) && !amdModulePath.includes("esri/applications")) {
|
|
201
|
-
return node;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (amdModulePath.includes("esri/applications") && !publicModules.includes(amdModulePath)) {
|
|
205
|
-
console.log(
|
|
206
|
-
"\x1b[33m",
|
|
207
|
-
"WARNING: Skipping, application module not in publicModules file in js-api repo: ",
|
|
208
|
-
amdModulePath,
|
|
209
|
-
);
|
|
210
|
-
return node;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// Ignore modules that are in the ignore list and the singletons that are already in the typeInfos array
|
|
214
|
-
if (ignoreModule(amdModulePath) || singletons.has(amdModulePath)) {
|
|
215
|
-
return node;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// Loop thru the module body
|
|
219
|
-
node.body?.forEachChild((statement) => {
|
|
220
|
-
// We are only interested in import equals declarations inside ModuleDeclarations
|
|
221
|
-
// For example:
|
|
222
|
-
// declare module "esri/identity/Credential" {
|
|
223
|
-
// import Credential = __esri.Credential; << This is what we are interested in
|
|
224
|
-
// export = Credential;
|
|
225
|
-
// }
|
|
226
|
-
if (!ts.isImportEqualsDeclaration(statement)) {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// Get the type name, i.g. `__esri.Credential` and validate that it is a class or interface
|
|
231
|
-
// in the public interfaces.
|
|
232
|
-
const typeName = statement.moduleReference.getText(typingsProgram);
|
|
233
|
-
if (!publicTypeValidator.validateType(typeName)) {
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// Validate that we can find the esm module file
|
|
238
|
-
const esmModulePath = convertAmdToEsmPath(amdModulePath);
|
|
239
|
-
const resolvedEsmModulePath = resolvePkg(esmModulePath);
|
|
240
|
-
if (!resolvedEsmModulePath || !fs.existsSync(resolvedEsmModulePath)) {
|
|
241
|
-
console.error(`Could not find esm module for: ${esmModulePath}`);
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// If the type has a constructor, we want to extract the parameters
|
|
246
|
-
// to inject the new function
|
|
247
|
-
const constructorParameters = extractConstructorParameters(statement);
|
|
248
|
-
|
|
249
|
-
// Get the symbol and extract details
|
|
250
|
-
typeInfos.push({ amdModulePath, esmModulePath, typeName, constructorParameters });
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
return node;
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
/** This is our entry point for the transformer */
|
|
258
|
-
function extractTypeInfos(context: ts.TransformationContext): ts.Transformer<ts.Node> {
|
|
259
|
-
const visit = createVisitor(context);
|
|
260
|
-
return (node: ts.Node) => ts.visitNode(node, visit);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
/** Serialize a class symbol information */
|
|
264
|
-
function extractConstructorParameters(statement: ts.ImportEqualsDeclaration): ParameterInfo[] | undefined {
|
|
265
|
-
// Get the symbol of the module reference
|
|
266
|
-
// Example: `import Credential = __esri.Credential;`
|
|
267
|
-
// In this example, `__esri.Credential` is the module reference
|
|
268
|
-
// We want to get the type of `__esri.Credential`
|
|
269
|
-
const symbol = checker.getSymbolAtLocation(statement.moduleReference);
|
|
270
|
-
if (!symbol) {
|
|
271
|
-
throw new Error("Symbol not found");
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// The constructor parameters are only relevant if the type has a constructor signature.
|
|
275
|
-
// We want to extract the constructor parameters for the first constructor signature.
|
|
276
|
-
// Example: `declare class Credential { constructor(properties: CredentialProperties); }`
|
|
277
|
-
// constructorParameters will be an array with one item: `{ name: "properties", type: "CredentialProperties" }` or undefined.
|
|
278
|
-
return checker
|
|
279
|
-
.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration!)
|
|
280
|
-
.getConstructSignatures()
|
|
281
|
-
.at(0)
|
|
282
|
-
?.getParameters()
|
|
283
|
-
.map<ParameterInfo>((parameterSymbol: ts.Symbol) => ({
|
|
284
|
-
name: parameterSymbol.getName(),
|
|
285
|
-
type: checker.typeToString(
|
|
286
|
-
checker.getTypeOfSymbolAtLocation(parameterSymbol, parameterSymbol.valueDeclaration!),
|
|
287
|
-
),
|
|
288
|
-
}));
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
// Use the transformer to visit the typings file
|
|
292
|
-
ts.transform(typingsProgram, [extractTypeInfos]);
|
|
293
|
-
|
|
294
|
-
// At this point the typeInfos array contains all the symbols we are interested in
|
|
295
|
-
for (const typeInfo of typeInfos) {
|
|
296
|
-
// Generate the import function
|
|
297
|
-
indexFileStatements.push(generateImportFunction(typeInfo));
|
|
298
|
-
|
|
299
|
-
// If we have constructor parameters, generate the new function
|
|
300
|
-
if (typeInfo.constructorParameters) {
|
|
301
|
-
indexFileStatements.push(generateNewFunction(typeInfo));
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
console.log("Modules converted to core-adapter: ", typeInfos.length);
|
|
306
|
-
|
|
307
|
-
const indexContent = indexFileStatements.join("\n");
|
|
308
|
-
fs.writeFile("src/index.ts", indexContent, (err) => {
|
|
309
|
-
if (err) {
|
|
310
|
-
console.error("Error generating adapter file:", err);
|
|
311
|
-
} else {
|
|
312
|
-
console.log("Adapter file generated.");
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
function generateNewFunction(entry: TypeInfo): string {
|
|
318
|
-
const { amdModulePath, typeName, constructorParameters } = entry;
|
|
319
|
-
if (!constructorParameters) {
|
|
320
|
-
throw new Error("Constructor parameters are required");
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
const functionNameSuffix = convertToPascalCase(amdModulePath);
|
|
324
|
-
|
|
325
|
-
// Generate the parameters declarations and the call arguments
|
|
326
|
-
const parameterDeclarations: string[] = [];
|
|
327
|
-
const callArgumentsParts: string[] = [];
|
|
328
|
-
for (const parameterInfo of constructorParameters) {
|
|
329
|
-
callArgumentsParts.push(parameterInfo.name);
|
|
330
|
-
|
|
331
|
-
// Do we have a union type?
|
|
332
|
-
if (parameterInfo.type.includes("|")) {
|
|
333
|
-
parameterDeclarations.push(processUnionType(parameterInfo));
|
|
334
|
-
continue;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
// Do we have a native type?
|
|
338
|
-
if (nativeTypes.some((x) => x.includes(parameterInfo.type || ""))) {
|
|
339
|
-
parameterDeclarations.push(`${parameterInfo.name}: ${parameterInfo.type}`);
|
|
340
|
-
continue;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
// Must be an esri type
|
|
344
|
-
parameterDeclarations.push(`${parameterInfo.name}: __esri.${parameterInfo.type}`);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
const parametersDeclaration = parameterDeclarations.join(", ");
|
|
348
|
-
const callArguments = callArgumentsParts.join(", ");
|
|
349
|
-
|
|
350
|
-
return `
|
|
351
|
-
export async function new${functionNameSuffix}(${parametersDeclaration}): Promise<${typeName}> {
|
|
352
|
-
const ModConstructor = await import${functionNameSuffix}();
|
|
353
|
-
return new ModConstructor(${callArguments});
|
|
354
|
-
}`;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* Process a parameter defined as a union type
|
|
359
|
-
*/
|
|
360
|
-
function processUnionType(parameterInfo: ParameterInfo): string {
|
|
361
|
-
// Split the union type into parts and process each part
|
|
362
|
-
const unionedTypesParts = parameterInfo.type.split("|");
|
|
363
|
-
const correctedUnionedTypes: string[] = [];
|
|
364
|
-
for (const unionTypesPart of unionedTypesParts) {
|
|
365
|
-
// Is the part a native type?
|
|
366
|
-
if (nativeArrayTypes.some((x) => unionTypesPart.includes(x))) {
|
|
367
|
-
correctedUnionedTypes.push(unionTypesPart);
|
|
368
|
-
continue;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
// Is the part a Collection type?
|
|
372
|
-
if (unionTypesPart.includes("Collection<")) {
|
|
373
|
-
// Handle Collection types
|
|
374
|
-
if (nativeGenericTypes.some((x) => unionTypesPart.includes(x))) {
|
|
375
|
-
correctedUnionedTypes.push(`__esri.${unionTypesPart.trim()}`);
|
|
376
|
-
} else {
|
|
377
|
-
const v = unionTypesPart.replace(/<(?<esriTypeName>[^>]+)>/gu, "<__esri.$1>");
|
|
378
|
-
correctedUnionedTypes.push(`__esri.${v.trim()}`);
|
|
379
|
-
}
|
|
380
|
-
continue;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
// Must be an esri type
|
|
384
|
-
correctedUnionedTypes.push(`__esri.${unionTypesPart.trim()}`);
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
// Re-assemble the unioned types
|
|
388
|
-
return `${parameterInfo.name}: ${correctedUnionedTypes.join(" | ")}`;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
/**
|
|
392
|
-
* Generate the normal import function
|
|
393
|
-
*/
|
|
394
|
-
function generateImportFunction(entry: TypeInfo): string {
|
|
395
|
-
const { amdModulePath, esmModulePath, typeName, instanceType = false } = entry;
|
|
396
|
-
const functionNameSuffix = convertToPascalCase(amdModulePath);
|
|
397
|
-
const resolvedTypeName = [
|
|
398
|
-
"__esri.CollectionFlattener",
|
|
399
|
-
"__esri.SelectionOperation",
|
|
400
|
-
"__esri.SketchTooltipControls",
|
|
401
|
-
].includes(typeName)
|
|
402
|
-
? "any"
|
|
403
|
-
: typeName;
|
|
404
|
-
|
|
405
|
-
let promiseType: string;
|
|
406
|
-
if (resolvedTypeName === "any") {
|
|
407
|
-
promiseType = "any";
|
|
408
|
-
} else if (instanceType) {
|
|
409
|
-
promiseType = resolvedTypeName;
|
|
410
|
-
} else {
|
|
411
|
-
promiseType = `typeof ${resolvedTypeName}`;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
return `
|
|
415
|
-
export async function import${functionNameSuffix}(): Promise<${promiseType}> {
|
|
416
|
-
if (isAMD) {
|
|
417
|
-
return await window.$arcgis.import("${amdModulePath}");
|
|
418
|
-
}
|
|
419
|
-
const module = await import("${esmModulePath}");
|
|
420
|
-
return isDefaultModule(module) ? module.default : module;
|
|
421
|
-
}`;
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
function upperFirst(s: string): string {
|
|
425
|
-
return s[0].toUpperCase() + s.slice(1);
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
function ignoreModule(s: string): boolean {
|
|
429
|
-
return ignoreExports.includes(s);
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* Convert a module path to a pascal case name without the `esri/` prefix.
|
|
434
|
-
* For example: `esri/identity/IdentityManager` becomes `IdentityIdentityManager`
|
|
435
|
-
*/
|
|
436
|
-
function convertToPascalCase(input: string): string {
|
|
437
|
-
// Split the string by slashes and remove any empty strings
|
|
438
|
-
const parts = input.replace("esri/", "").split("/").filter(Boolean);
|
|
439
|
-
|
|
440
|
-
// Capitalize the first letter of each part
|
|
441
|
-
const pascalCaseParts = parts.map(upperFirst);
|
|
442
|
-
|
|
443
|
-
// Join the parts together
|
|
444
|
-
return pascalCaseParts.join("");
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
function convertAmdToEsmPath(amdPath: string): string {
|
|
448
|
-
return amdPath.replace("esri/", "@arcgis/core/").replace(/(\.js)?$/u, ".js");
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
generate();
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import https from "node:https";
|
|
3
|
-
import resolvePkg from "resolve-pkg";
|
|
4
|
-
|
|
5
|
-
// Get the @arcgis/core installed version
|
|
6
|
-
const corePackagePath = resolvePkg("@arcgis/core/package.json");
|
|
7
|
-
if (!corePackagePath) {
|
|
8
|
-
console.error("Unable to find @arcgis/core package.json");
|
|
9
|
-
process.exit(1);
|
|
10
|
-
}
|
|
11
|
-
const corePackage = JSON.parse(fs.readFileSync(corePackagePath, "utf-8")) as { version: string };
|
|
12
|
-
const coreVersion = corePackage.version.split(".").slice(0, 2).join(".");
|
|
13
|
-
console.log(`Using ArcGIS Typings version ${coreVersion}`);
|
|
14
|
-
|
|
15
|
-
// The typings are hosted on jsapi.esri.com and are versioned based on the system version.
|
|
16
|
-
const files = [
|
|
17
|
-
{
|
|
18
|
-
source: `https://jsapi.esri.com/typings/arcgis-js-api-${coreVersion}.d.ts`,
|
|
19
|
-
destination: `${process.cwd()}/support/arcgis.d.ts`,
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
source: `https://jsapi.esri.com/typings/api-reference-esm-imports-${coreVersion}.json`,
|
|
23
|
-
destination: `${process.cwd()}/support/api-reference-esm-imports.json`,
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
source: "https://raw.devtopia.esri.com/WebGIS/arcgis-js-api/4master/build/publicModules.mjs",
|
|
27
|
-
destination: `${process.cwd()}/support/publicModules.ts`,
|
|
28
|
-
},
|
|
29
|
-
];
|
|
30
|
-
|
|
31
|
-
const HttpOK = 200;
|
|
32
|
-
|
|
33
|
-
// Download the typings and support files.
|
|
34
|
-
async function downloadSupportFiles(source: string, destination: string): Promise<void> {
|
|
35
|
-
await new Promise((resolve, reject) => {
|
|
36
|
-
const isPublicModules = source.includes("publicModules.mjs");
|
|
37
|
-
const options: {
|
|
38
|
-
headers?: {
|
|
39
|
-
Authorization: string;
|
|
40
|
-
};
|
|
41
|
-
} = {};
|
|
42
|
-
if (isPublicModules) {
|
|
43
|
-
options.headers = {
|
|
44
|
-
Authorization: `Token ${process.env.DEVTOPIA_TOKEN}`,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
https.get(source, options, (resp) => {
|
|
48
|
-
const file = resp.statusCode === HttpOK ? fs.createWriteStream(destination) : undefined;
|
|
49
|
-
console.log("Downloaded:", source);
|
|
50
|
-
console.log(`Response type: ${resp.headers["content-type"]}`);
|
|
51
|
-
|
|
52
|
-
if (resp.statusCode !== HttpOK) {
|
|
53
|
-
console.error(`Request failed for ${source}:`, resp.statusMessage);
|
|
54
|
-
console.error(`Skipping: ${destination}`);
|
|
55
|
-
file?.close();
|
|
56
|
-
resolve(undefined);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (isPublicModules) {
|
|
60
|
-
let body = "";
|
|
61
|
-
resp.on("data", (chunk) => {
|
|
62
|
-
body += chunk;
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
resp.on("end", () => {
|
|
66
|
-
const regex = /const\s+publicModules\s*=\s*\[(.*?)\];/su;
|
|
67
|
-
const match = body.match(regex);
|
|
68
|
-
if (match) {
|
|
69
|
-
const publicModules = match[1];
|
|
70
|
-
body = `export const publicModules = [${publicModules}];`;
|
|
71
|
-
file?.write(body);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
} else {
|
|
75
|
-
resp.pipe(file!);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
resp.on("error", (err) => {
|
|
79
|
-
console.error(`Request error for ${source}:`, err);
|
|
80
|
-
reject(err);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
file?.on("error", (err) => {
|
|
84
|
-
console.error(`Writing error for ${destination}:`, err);
|
|
85
|
-
reject(err);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
file?.on("finish", () => {
|
|
89
|
-
file?.close();
|
|
90
|
-
resolve(undefined);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
Promise.allSettled(
|
|
97
|
-
files.map(async ({ source, destination }): Promise<void> => await downloadSupportFiles(source, destination)),
|
|
98
|
-
)
|
|
99
|
-
.then(() => {
|
|
100
|
-
console.log(`ArcGIS Typings and support files for ${coreVersion} updated`);
|
|
101
|
-
})
|
|
102
|
-
.catch((err: Error) => {
|
|
103
|
-
console.error(err.message);
|
|
104
|
-
process.exit(1);
|
|
105
|
-
});
|