@osdk/foundry-sdk-generator 1.3.12 → 1.3.14
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/CHANGELOG.md +22 -0
- package/build/browser/index.js +258 -178
- package/build/browser/index.js.map +1 -1
- package/build/cjs/__e2e_tests__/consola.d.cts +1 -47
- package/build/cjs/__e2e_tests__/consola.d.ts.map +1 -1
- package/build/cjs/__e2e_tests__/testSetup.d.ts.map +1 -1
- package/build/cjs/generate/betaClient/bundleDependencies.d.ts.map +1 -1
- package/build/cjs/generate/betaClient/copyFiles.d.ts.map +1 -1
- package/build/cjs/generate/betaClient/generatePackage.d.ts.map +1 -1
- package/build/cjs/generate/betaClient/getModuleSourceFile.d.cts +2 -1
- package/build/cjs/generate/betaClient/getModuleSourceFile.d.ts.map +1 -1
- package/build/cjs/generate/betaClient/minifyBundle.d.cts +7 -3
- package/build/cjs/generate/betaClient/minifyBundle.d.ts.map +1 -1
- package/build/cjs/index.cjs +257 -177
- package/build/cjs/index.cjs.map +1 -1
- package/build/esm/__e2e_tests__/consola.d.ts +1 -47
- package/build/esm/__e2e_tests__/consola.d.ts.map +1 -1
- package/build/esm/__e2e_tests__/testSetup.d.ts.map +1 -1
- package/build/esm/generate/betaClient/bundleDependencies.d.ts.map +1 -1
- package/build/esm/generate/betaClient/copyFiles.d.ts.map +1 -1
- package/build/esm/generate/betaClient/generatePackage.d.ts.map +1 -1
- package/build/esm/generate/betaClient/getModuleSourceFile.d.ts +2 -1
- package/build/esm/generate/betaClient/getModuleSourceFile.d.ts.map +1 -1
- package/build/esm/generate/betaClient/minifyBundle.d.ts +7 -3
- package/build/esm/generate/betaClient/minifyBundle.d.ts.map +1 -1
- package/build/esm/index.js +258 -178
- package/build/esm/index.js.map +1 -1
- package/package.json +15 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @osdk/foundry-sdk-generator
|
|
2
2
|
|
|
3
|
+
## 1.3.14
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [507ae4a]
|
|
8
|
+
- Updated dependencies [d67e753]
|
|
9
|
+
- @osdk/generator@1.13.6
|
|
10
|
+
- @osdk/legacy-client@2.5.4
|
|
11
|
+
- @osdk/shared.net@1.12.3
|
|
12
|
+
- @osdk/client@0.21.3
|
|
13
|
+
- @osdk/api@1.9.3
|
|
14
|
+
- @osdk/client.api@0.21.3
|
|
15
|
+
|
|
16
|
+
## 1.3.13
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- 03fbf31: Fixes .d.ts generation for slate
|
|
21
|
+
- Updated dependencies [03fbf31]
|
|
22
|
+
- @osdk/legacy-client@2.5.3
|
|
23
|
+
- @osdk/generator@1.13.5
|
|
24
|
+
|
|
3
25
|
## 1.3.12
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/build/browser/index.js
CHANGED
|
@@ -12,8 +12,9 @@ import commonjs from '@rollup/plugin-commonjs';
|
|
|
12
12
|
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
13
13
|
import { rollup } from 'rollup';
|
|
14
14
|
import nodePolyfill from 'rollup-plugin-polyfill-node';
|
|
15
|
-
import { Project,
|
|
15
|
+
import { Project, SyntaxKind, Node } from 'ts-morph';
|
|
16
16
|
import * as fs from 'fs';
|
|
17
|
+
import { colorize } from 'consola/utils';
|
|
17
18
|
import { ModuleKind, ScriptTarget, createCompilerHost, createSourceFile, createProgram } from 'typescript';
|
|
18
19
|
|
|
19
20
|
// src/cli/foundrySdkGeneratorCli.ts
|
|
@@ -558,7 +559,7 @@ function isValidSemver(semverString) {
|
|
|
558
559
|
}
|
|
559
560
|
|
|
560
561
|
// src/utils/UserAgent.ts
|
|
561
|
-
var USER_AGENT = `typescript-sdk-generator/${"1.3.
|
|
562
|
+
var USER_AGENT = `typescript-sdk-generator/${"1.3.14"}`;
|
|
562
563
|
async function createRollupBuild(absolutePackagePath, packageName) {
|
|
563
564
|
const inputPath = `${absolutePackagePath}/${packageName}/index.js`;
|
|
564
565
|
const {
|
|
@@ -601,166 +602,25 @@ async function generateEsmBuild(absolutePackagePath, packageName) {
|
|
|
601
602
|
async function generateBundles(absolutePackagePath, packageName) {
|
|
602
603
|
await Promise.all([generateEsmBuild(absolutePackagePath, packageName)]);
|
|
603
604
|
}
|
|
604
|
-
|
|
605
|
-
// src/generate/betaClient/getModuleSourceFile.ts
|
|
606
|
-
function getModuleSourceFile(project, node) {
|
|
607
|
-
let exportSourceFile;
|
|
608
|
-
try {
|
|
609
|
-
exportSourceFile = project.getSourceFile(`/${node.getLiteralText()}.ts`);
|
|
610
|
-
if (!exportSourceFile) {
|
|
611
|
-
exportSourceFile = project.getSourceFile(`/${node.getLiteralText()}/index.ts`);
|
|
612
|
-
if (!exportSourceFile) {
|
|
613
|
-
return void 0;
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
} catch (e) {
|
|
617
|
-
return void 0;
|
|
618
|
-
}
|
|
619
|
-
return exportSourceFile;
|
|
620
|
-
}
|
|
621
|
-
function withoutTrailingIndex(filePath) {
|
|
622
|
-
return filePath.endsWith("/index") ? filePath.slice(0, -6) : filePath;
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
// src/generate/betaClient/copyFiles.ts
|
|
626
|
-
var KNOWN_EXTERNAL = /* @__PURE__ */ new Set(["geojson"]);
|
|
627
|
-
function removeDts(file) {
|
|
628
|
-
return file.replace(/\.d\.c?ts$/, "");
|
|
629
|
-
}
|
|
630
|
-
async function copyFiles(project, dirs, generatedPackageName, generatedFiles) {
|
|
631
|
-
const importSet = /* @__PURE__ */ new Set();
|
|
632
|
-
for (const [fileName, file] of Object.entries(generatedFiles)) {
|
|
633
|
-
if (!fileName.endsWith(".d.ts") && !fileName.endsWith(".d.cts")) {
|
|
634
|
-
continue;
|
|
635
|
-
}
|
|
636
|
-
const indexOfPackageName = fileName.indexOf(generatedPackageName);
|
|
637
|
-
const tsPath = removeDts(fileName.slice(indexOfPackageName + generatedPackageName.length));
|
|
638
|
-
const newModulePath = `${generatedPackageName}${tsPath}`;
|
|
639
|
-
const sourceFile = project.createSourceFile(newModulePath, file);
|
|
640
|
-
for (const importDeclaration of sourceFile.getImportDeclarations()) {
|
|
641
|
-
const moduleSpecifier = importDeclaration.getModuleSpecifier();
|
|
642
|
-
const newModuleSpecifier = transformModuleSpecifier(moduleSpecifier.getLiteralValue(), newModulePath);
|
|
643
|
-
moduleSpecifier.setLiteralValue(newModuleSpecifier);
|
|
644
|
-
if (newModuleSpecifier.startsWith("internal")) {
|
|
645
|
-
for (const importName of importDeclaration.getNamedImports().map((imp) => imp.getName())) {
|
|
646
|
-
importSet.add(importName);
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
for (const exportedDecl of sourceFile.getStatements()) {
|
|
651
|
-
if (Node.isModifierable(exportedDecl)) {
|
|
652
|
-
exportedDecl.toggleModifier("declare", false);
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
for (const exportDeclaration of sourceFile.getExportDeclarations()) {
|
|
656
|
-
const moduleSpecifier = exportDeclaration.getModuleSpecifier();
|
|
657
|
-
if (moduleSpecifier) {
|
|
658
|
-
const newModuleSpecifier = transformModuleSpecifier(moduleSpecifier.getLiteralValue(), newModulePath);
|
|
659
|
-
moduleSpecifier.setLiteralValue(newModuleSpecifier);
|
|
660
|
-
if (newModuleSpecifier.startsWith("internal")) {
|
|
661
|
-
for (const exportName of exportDeclaration.getNamedExports().map((exp) => exp.getName())) {
|
|
662
|
-
importSet.add(exportName);
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
for (const dir of dirs) {
|
|
669
|
-
const buildDirsToTry = ["build/cjs", "build/esm"];
|
|
670
|
-
const packageName = getPackageName(dir);
|
|
671
|
-
const relativeBuildDir = buildDirsToTry.find((buildDir) => {
|
|
672
|
-
return ["d.ts", "d.cts", "d.mts"].some((ext) => {
|
|
673
|
-
try {
|
|
674
|
-
fs.statSync(path.join(dir, buildDir, `index.${ext}`));
|
|
675
|
-
return true;
|
|
676
|
-
} catch (e) {
|
|
677
|
-
return false;
|
|
678
|
-
}
|
|
679
|
-
});
|
|
680
|
-
});
|
|
681
|
-
if (!relativeBuildDir) {
|
|
682
|
-
throw new Error("Couldn't find the right build dir");
|
|
683
|
-
}
|
|
684
|
-
for (const file of getTypeFiles(path.join(dir, relativeBuildDir))) {
|
|
685
|
-
const absoluteBuildDir = path.join(dir, relativeBuildDir);
|
|
686
|
-
const tsPath = removeDts(path.relative(absoluteBuildDir, file));
|
|
687
|
-
const newModulePath = `internal/${packageName}/${tsPath}`;
|
|
688
|
-
const fileContents = fs.readFileSync(file).toString();
|
|
689
|
-
const sourceFile = project.createSourceFile(`${newModulePath}.ts`, fileContents, {
|
|
690
|
-
overwrite: true
|
|
691
|
-
});
|
|
692
|
-
for (const importDeclaration of sourceFile.getImportDeclarations()) {
|
|
693
|
-
const moduleSpecifier = importDeclaration.getModuleSpecifier();
|
|
694
|
-
const newModuleSpecifier = transformModuleSpecifier(moduleSpecifier.getLiteralValue(), newModulePath);
|
|
695
|
-
moduleSpecifier.setLiteralValue(newModuleSpecifier);
|
|
696
|
-
}
|
|
697
|
-
for (const exportedDecl of sourceFile.getStatements()) {
|
|
698
|
-
if (Node.isModifierable(exportedDecl)) {
|
|
699
|
-
exportedDecl.toggleModifier("declare", false);
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
for (const exportDeclaration of sourceFile.getExportDeclarations()) {
|
|
703
|
-
const moduleSpecifier = exportDeclaration.getModuleSpecifier();
|
|
704
|
-
if (moduleSpecifier) {
|
|
705
|
-
const newModuleSpecifier = transformModuleSpecifier(moduleSpecifier.getLiteralValue(), newModulePath);
|
|
706
|
-
moduleSpecifier.setLiteralValue(withoutTrailingIndex(newModuleSpecifier));
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
return importSet;
|
|
712
|
-
}
|
|
713
|
-
function getPackageName(dir) {
|
|
714
|
-
const pkg = fs.readFileSync(path.join(dir, "package.json"));
|
|
715
|
-
const parsed = JSON.parse(pkg.toString());
|
|
716
|
-
return parsed.name;
|
|
717
|
-
}
|
|
718
|
-
function* getTypeFiles(dir) {
|
|
719
|
-
for (const item of fs.readdirSync(dir)) {
|
|
720
|
-
const target = path.join(dir, item);
|
|
721
|
-
if (target.endsWith(".d.ts") && !target.endsWith(".test.d.ts") || target.endsWith(".d.cts") && !target.endsWith(".test.d.cts")) {
|
|
722
|
-
yield target;
|
|
723
|
-
} else {
|
|
724
|
-
const stat = fs.lstatSync(target);
|
|
725
|
-
if (stat.isDirectory() && item !== "test") {
|
|
726
|
-
yield* getTypeFiles(target);
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
function transformModuleSpecifier(value, filePath) {
|
|
732
|
-
let moduleSpecifier;
|
|
733
|
-
if (value.startsWith("@osdk")) {
|
|
734
|
-
if (value.startsWith("@osdk/gateway/types")) {
|
|
735
|
-
moduleSpecifier = `internal/${value.replace("@osdk/gateway/types", "@osdk/gateway/public/types")}`;
|
|
736
|
-
} else {
|
|
737
|
-
moduleSpecifier = `internal/${value}`;
|
|
738
|
-
}
|
|
739
|
-
} else if (value.startsWith(".")) {
|
|
740
|
-
moduleSpecifier = path.join(filePath, "..", value);
|
|
741
|
-
} else if (KNOWN_EXTERNAL.has(value)) {
|
|
742
|
-
moduleSpecifier = `internal/${value}`;
|
|
743
|
-
} else {
|
|
744
|
-
throw new Error("Failed generated DTS for package, no handling for: " + value);
|
|
745
|
-
}
|
|
746
|
-
return withoutTrailingIndex(withoutExtension(moduleSpecifier));
|
|
747
|
-
}
|
|
748
|
-
function withoutExtension(value) {
|
|
749
|
-
return value.replace(".js", "");
|
|
750
|
-
}
|
|
605
|
+
var DEBUG = false;
|
|
751
606
|
var ProjectMinifier = class {
|
|
752
607
|
nodesToKeep = {};
|
|
753
608
|
visitedImports = {};
|
|
754
609
|
dependentExport = {};
|
|
755
610
|
stack = [];
|
|
756
|
-
constructor(project, startingImportSet
|
|
611
|
+
constructor(project, startingImportSet) {
|
|
757
612
|
this.project = project;
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
613
|
+
const filesToImports = {};
|
|
614
|
+
for (const importSet of startingImportSet) {
|
|
615
|
+
const [file, importString] = importSet.split(":");
|
|
616
|
+
if (!filesToImports[file]) {
|
|
617
|
+
filesToImports[file] = /* @__PURE__ */ new Set();
|
|
618
|
+
}
|
|
619
|
+
filesToImports[file].add(importString);
|
|
620
|
+
}
|
|
621
|
+
for (const [file, imports] of Object.entries(filesToImports)) {
|
|
622
|
+
this.pushNextVisit(getModuleSourceFile(project, file), imports, "constructor");
|
|
623
|
+
}
|
|
764
624
|
}
|
|
765
625
|
shouldContinueVisiting() {
|
|
766
626
|
return this.stack.length > 0;
|
|
@@ -771,7 +631,8 @@ var ProjectMinifier = class {
|
|
|
771
631
|
}
|
|
772
632
|
return this.stack.pop();
|
|
773
633
|
}
|
|
774
|
-
pushNextVisit(sourceFile, imports) {
|
|
634
|
+
pushNextVisit(sourceFile, imports, source) {
|
|
635
|
+
if (imports.size === 0) return;
|
|
775
636
|
this.stack.push({
|
|
776
637
|
sourceFile,
|
|
777
638
|
imports
|
|
@@ -787,6 +648,8 @@ var ProjectMinifier = class {
|
|
|
787
648
|
if (!this.visitedImports[filePath].has(importToCheck)) {
|
|
788
649
|
shouldSkipCheck = false;
|
|
789
650
|
this.visitedImports[filePath].add(importToCheck);
|
|
651
|
+
} else {
|
|
652
|
+
traversalStep.imports.delete(importToCheck);
|
|
790
653
|
}
|
|
791
654
|
}
|
|
792
655
|
return shouldSkipCheck;
|
|
@@ -806,15 +669,23 @@ var ProjectMinifier = class {
|
|
|
806
669
|
const identifiersToResolve = /* @__PURE__ */ new Set();
|
|
807
670
|
const sourceFile = visitImports.sourceFile;
|
|
808
671
|
const moduleName = getModuleFromFileName(sourceFile);
|
|
809
|
-
const
|
|
672
|
+
const nodesToKeepForThisModule = this.getNodesToKeepForModule(moduleName);
|
|
810
673
|
for (const [key, declarations] of sourceFile.getExportedDeclarations()) {
|
|
674
|
+
if (declarations.length === 0 && DEBUG) {
|
|
675
|
+
console.log(`Possible issue for sdk with slate: can't find declaration for ${key} from ${logNode(sourceFile)}`);
|
|
676
|
+
}
|
|
811
677
|
if (!visitImports.imports.has(key)) {
|
|
812
678
|
continue;
|
|
813
679
|
}
|
|
814
680
|
this.visitDependentExports(moduleName);
|
|
815
|
-
this.visitDeclaration(declarations,
|
|
681
|
+
this.visitDeclaration(declarations, nodesToKeepForThisModule, identifiersToResolve);
|
|
816
682
|
}
|
|
817
683
|
for (const declaration of sourceFile.getExportDeclarations()) {
|
|
684
|
+
let deleteFromSet2 = function(set, toDelete) {
|
|
685
|
+
for (const d of toDelete) {
|
|
686
|
+
set.delete(d);
|
|
687
|
+
}
|
|
688
|
+
};
|
|
818
689
|
const moduleSpecifier = declaration.getModuleSpecifier();
|
|
819
690
|
if (!moduleSpecifier) {
|
|
820
691
|
continue;
|
|
@@ -832,20 +703,28 @@ var ProjectMinifier = class {
|
|
|
832
703
|
const nodesToKeepForModule = this.getNodesToKeepForModule(getModuleFromFileName(exportSourceFile));
|
|
833
704
|
nodesToKeepForModule.add(exportSourceFile);
|
|
834
705
|
const importsFromNamespace = new Set(exportSourceFile.getExportedDeclarations().keys());
|
|
835
|
-
this.pushNextVisit(exportSourceFile, importsFromNamespace);
|
|
706
|
+
this.pushNextVisit(exportSourceFile, importsFromNamespace, "minifyProjectA");
|
|
836
707
|
}
|
|
837
708
|
}
|
|
838
709
|
}
|
|
839
710
|
const namedExports = declaration.getNamedExports();
|
|
840
711
|
if (namedExports.length === 0) {
|
|
841
|
-
|
|
712
|
+
const depExportNames = new Set(exportSourceFile.getExportSymbols().map((s) => s.getName()).filter((s) => visitImports.imports.has(s)));
|
|
713
|
+
deleteFromSet2(visitImports.imports, depExportNames);
|
|
714
|
+
this.pushNextVisit(exportSourceFile, depExportNames, "minifyProjectB");
|
|
842
715
|
if (!this.dependentExport[literalText]) {
|
|
843
716
|
this.dependentExport[literalText] = /* @__PURE__ */ new Set();
|
|
844
717
|
}
|
|
845
718
|
this.dependentExport[literalText].add(declaration);
|
|
846
719
|
continue;
|
|
847
720
|
}
|
|
848
|
-
this.visitNamedExports(namedExports, visitImports,
|
|
721
|
+
this.visitNamedExports(namedExports, visitImports, nodesToKeepForThisModule, exportSourceFile);
|
|
722
|
+
for (const n of namedExports) {
|
|
723
|
+
if (visitImports.imports.has(n.getName())) {
|
|
724
|
+
nodesToKeepForThisModule.add(n);
|
|
725
|
+
visitImports.imports.delete(n.getName());
|
|
726
|
+
}
|
|
727
|
+
}
|
|
849
728
|
}
|
|
850
729
|
for (const declaration of sourceFile.getImportDeclarations()) {
|
|
851
730
|
const namedImports = declaration.getNamedImports();
|
|
@@ -866,12 +745,21 @@ var ProjectMinifier = class {
|
|
|
866
745
|
this.getNodesToKeepForModule(moduleSpecifier.getLiteralText()).add(decl);
|
|
867
746
|
});
|
|
868
747
|
this.getNodesToKeepForModule(moduleSpecifier.getLiteralText()).add(sourceFile);
|
|
869
|
-
this.pushNextVisit(importSourceFile, importsFromNamespace);
|
|
748
|
+
this.pushNextVisit(importSourceFile, importsFromNamespace, "minifyProjectC");
|
|
870
749
|
}
|
|
871
750
|
continue;
|
|
872
751
|
}
|
|
873
752
|
this.visitNamedImports(namedImports, identifiersToResolve, moduleName, declaration, importSourceFile);
|
|
874
753
|
}
|
|
754
|
+
sourceFile.getDescendantsOfKind(SyntaxKind.ImportType).forEach((node) => {
|
|
755
|
+
const moduleSpecifier = node.getArgument().getText().slice(1, -1);
|
|
756
|
+
const importSourceFile = getModuleSourceFile(this.project, moduleSpecifier);
|
|
757
|
+
const qualifier = node.getQualifier();
|
|
758
|
+
const qualifierSymbol = qualifier?.getSymbol();
|
|
759
|
+
if (qualifier && qualifierSymbol && importSourceFile && identifiersToResolve.has(qualifierSymbol)) {
|
|
760
|
+
this.pushNextVisit(importSourceFile, /* @__PURE__ */ new Set([qualifier.getText()]), "dynamic imports");
|
|
761
|
+
}
|
|
762
|
+
});
|
|
875
763
|
}
|
|
876
764
|
this.deleteUnused();
|
|
877
765
|
}
|
|
@@ -889,7 +777,7 @@ var ProjectMinifier = class {
|
|
|
889
777
|
this.getNodesToKeepForModule(moduleName).add(declaration);
|
|
890
778
|
}
|
|
891
779
|
}
|
|
892
|
-
this.pushNextVisit(importSourceFile, importsToVisit);
|
|
780
|
+
this.pushNextVisit(importSourceFile, importsToVisit, "visitNamedImports");
|
|
893
781
|
}
|
|
894
782
|
// For each named export if it is something that we need, we keep the export
|
|
895
783
|
// And visit the module it is exported from
|
|
@@ -910,33 +798,33 @@ var ProjectMinifier = class {
|
|
|
910
798
|
nodeSet.add(ancestor);
|
|
911
799
|
}
|
|
912
800
|
}
|
|
913
|
-
this.pushNextVisit(exportSourceFile, exportsToVisit);
|
|
801
|
+
this.pushNextVisit(exportSourceFile, exportsToVisit, "visitNamedExports");
|
|
914
802
|
}
|
|
915
803
|
// Traverse the declaration and it's dependent symbols
|
|
916
|
-
visitDeclaration(declarations,
|
|
917
|
-
const declarationStack = declarations;
|
|
804
|
+
visitDeclaration(declarations, nodesToKeep, identifiersToResolve) {
|
|
805
|
+
const declarationStack = [...declarations];
|
|
918
806
|
while (declarationStack.length > 0) {
|
|
919
807
|
const currentDeclaration = declarationStack.pop();
|
|
920
|
-
if (
|
|
808
|
+
if (nodesToKeep.has(currentDeclaration)) {
|
|
921
809
|
continue;
|
|
922
810
|
}
|
|
923
|
-
|
|
811
|
+
nodesToKeep.add(currentDeclaration);
|
|
924
812
|
for (const ancestor of currentDeclaration.getAncestors()) {
|
|
925
|
-
|
|
813
|
+
nodesToKeep.add(ancestor);
|
|
926
814
|
}
|
|
927
815
|
for (const child of currentDeclaration.getDescendantsOfKind(SyntaxKind.Identifier)) {
|
|
928
816
|
const symbol = child.getSymbol();
|
|
929
|
-
if (!symbol ||
|
|
817
|
+
if (!symbol || identifiersToResolve.has(symbol)) {
|
|
930
818
|
continue;
|
|
931
819
|
}
|
|
932
|
-
|
|
820
|
+
identifiersToResolve.add(symbol);
|
|
933
821
|
for (const symbolDeclaration of symbol.getDeclarations()) {
|
|
934
822
|
if (Node.isImportDeclaration(symbolDeclaration)) {
|
|
935
823
|
const importSourceFile = getModuleSourceFile(this.project, symbolDeclaration.getModuleSpecifier());
|
|
936
824
|
if (!importSourceFile) {
|
|
937
825
|
continue;
|
|
938
826
|
}
|
|
939
|
-
this.pushNextVisit(importSourceFile, new Set(symbol.getName()));
|
|
827
|
+
this.pushNextVisit(importSourceFile, new Set(symbol.getName()), "visitDeclaration");
|
|
940
828
|
} else {
|
|
941
829
|
declarationStack.push(symbolDeclaration);
|
|
942
830
|
}
|
|
@@ -976,7 +864,17 @@ var ProjectMinifier = class {
|
|
|
976
864
|
exportDeclaration.remove();
|
|
977
865
|
continue;
|
|
978
866
|
}
|
|
979
|
-
for (const namedExport of exportDeclaration.getNamedExports()) {
|
|
867
|
+
perNamedExport: for (const namedExport of exportDeclaration.getNamedExports()) {
|
|
868
|
+
for (const n of nodesToKeepForTargetModule) {
|
|
869
|
+
if (Node.isExportable(n) && n.getSourceFile().getFilePath().startsWith("/internal")) {
|
|
870
|
+
if (n.getSymbol()?.getName() === namedExport.getName()) {
|
|
871
|
+
continue perNamedExport;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
if (nodesToKeepForModule.has(namedExport)) {
|
|
876
|
+
continue perNamedExport;
|
|
877
|
+
}
|
|
980
878
|
if (!nodesToKeepForTargetModule.has(namedExport)) {
|
|
981
879
|
namedExport.remove();
|
|
982
880
|
}
|
|
@@ -1019,6 +917,184 @@ var ProjectMinifier = class {
|
|
|
1019
917
|
function getModuleFromFileName(sourceFile) {
|
|
1020
918
|
return sourceFile.getFilePath().replace("/", "").replace(".ts", "").replace("/index", "");
|
|
1021
919
|
}
|
|
920
|
+
function logFilename(node) {
|
|
921
|
+
if (typeof node === "string") {
|
|
922
|
+
return colorize("yellow", node);
|
|
923
|
+
}
|
|
924
|
+
return colorize("yellow", `${node.getSourceFile().getFilePath()}:${node.getStartLineNumber()}`);
|
|
925
|
+
}
|
|
926
|
+
function logNode(node, {
|
|
927
|
+
ancestors,
|
|
928
|
+
text
|
|
929
|
+
} = {
|
|
930
|
+
ancestors: false,
|
|
931
|
+
text: true
|
|
932
|
+
}) {
|
|
933
|
+
if (Node.isSourceFile(node)) {
|
|
934
|
+
return `${colorize("blue", "SourceFile[")}${logFilename(node)}${colorize("blue", "]")}`;
|
|
935
|
+
}
|
|
936
|
+
return `${colorize("blue", "Node[")}${logFilename(node)}: ${colorize("gray", node.getKindName())}${ancestors ? `:${node.getAncestors().map((n) => n.getKindName()).join(":")}` : ""}${text ? `:${logJustNodeText(node)}` : ""}${colorize("blue", "]")}`;
|
|
937
|
+
}
|
|
938
|
+
function logJustNodeText(node, {
|
|
939
|
+
maxLength
|
|
940
|
+
} = {
|
|
941
|
+
maxLength: 50
|
|
942
|
+
}) {
|
|
943
|
+
const a = node.getText().replace(/\n/g, "\\n");
|
|
944
|
+
if (a.length <= maxLength) return `\`${a}\``;
|
|
945
|
+
return `\`${a.slice(0, maxLength)}\`...`;
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
// src/generate/betaClient/getModuleSourceFile.ts
|
|
949
|
+
var splitExtension = /^(.*)(\.[cm]?js)$/;
|
|
950
|
+
function getModuleSourceFile(project, node) {
|
|
951
|
+
let exportSourceFile;
|
|
952
|
+
const literalText = typeof node === "string" ? node : node.getLiteralText();
|
|
953
|
+
const withoutExtension2 = literalText.match(splitExtension)?.[1] ?? literalText;
|
|
954
|
+
try {
|
|
955
|
+
exportSourceFile = project.getSourceFile(`/${withoutExtension2}.ts`);
|
|
956
|
+
if (!exportSourceFile) {
|
|
957
|
+
exportSourceFile = project.getSourceFile(`/${withoutExtension2}/index.ts`);
|
|
958
|
+
if (DEBUG && !exportSourceFile) ;
|
|
959
|
+
}
|
|
960
|
+
} catch (e) {
|
|
961
|
+
console.log(e);
|
|
962
|
+
return void 0;
|
|
963
|
+
}
|
|
964
|
+
return exportSourceFile;
|
|
965
|
+
}
|
|
966
|
+
function withoutTrailingIndex(filePath) {
|
|
967
|
+
return filePath.endsWith("/index") ? filePath.slice(0, -6) : filePath;
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
// src/generate/betaClient/copyFiles.ts
|
|
971
|
+
var KNOWN_EXTERNAL = /* @__PURE__ */ new Set(["geojson"]);
|
|
972
|
+
function removeDts(file) {
|
|
973
|
+
return file.replace(/\.d\.c?ts$/, "");
|
|
974
|
+
}
|
|
975
|
+
async function copyFiles(project, dirs, generatedPackageName, generatedFiles) {
|
|
976
|
+
const importSet = /* @__PURE__ */ new Set();
|
|
977
|
+
for (const [fileName, file] of Object.entries(generatedFiles)) {
|
|
978
|
+
if (!fileName.endsWith(".d.ts") && !fileName.endsWith(".d.cts")) {
|
|
979
|
+
continue;
|
|
980
|
+
}
|
|
981
|
+
const indexOfPackageName = fileName.indexOf(generatedPackageName);
|
|
982
|
+
const tsPath = removeDts(fileName.slice(indexOfPackageName + generatedPackageName.length));
|
|
983
|
+
const newModulePath = `${generatedPackageName}${tsPath}`;
|
|
984
|
+
const sourceFile = project.createSourceFile(newModulePath, file);
|
|
985
|
+
remapImportsExports(sourceFile, newModulePath, importSet);
|
|
986
|
+
}
|
|
987
|
+
for (const dir of dirs) {
|
|
988
|
+
const buildDirsToTry = [path.join(dir, "build", "cjs"), path.join(dir, "build", "esm"), dir];
|
|
989
|
+
const packageName = getPackageName(dir);
|
|
990
|
+
const absoluteBuildDir = buildDirsToTry.find((buildDir) => {
|
|
991
|
+
return ["d.ts", "d.cts", "d.mts"].some((ext) => {
|
|
992
|
+
try {
|
|
993
|
+
fs.statSync(path.join(buildDir, `index.${ext}`));
|
|
994
|
+
return true;
|
|
995
|
+
} catch (e) {
|
|
996
|
+
return false;
|
|
997
|
+
}
|
|
998
|
+
});
|
|
999
|
+
});
|
|
1000
|
+
if (!absoluteBuildDir) {
|
|
1001
|
+
throw new Error("Couldn't find the right build dir");
|
|
1002
|
+
}
|
|
1003
|
+
for (const file of getTypeFiles(absoluteBuildDir)) {
|
|
1004
|
+
const tsPath = removeDts(path.relative(absoluteBuildDir, file));
|
|
1005
|
+
const newModulePath = `internal/${packageName}/${tsPath}`;
|
|
1006
|
+
const fileContents = fs.readFileSync(file).toString();
|
|
1007
|
+
const sourceFile = project.createSourceFile(`${newModulePath}.ts`, fileContents, {
|
|
1008
|
+
overwrite: true
|
|
1009
|
+
});
|
|
1010
|
+
remapImportsExports(sourceFile, newModulePath, void 0);
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
return importSet;
|
|
1014
|
+
}
|
|
1015
|
+
function remapImportsExports(sourceFile, newModulePath, importSet) {
|
|
1016
|
+
for (const importDeclaration of sourceFile.getImportDeclarations()) {
|
|
1017
|
+
const moduleSpecifier = importDeclaration.getModuleSpecifier();
|
|
1018
|
+
const newModuleSpecifier = transformModuleSpecifier(moduleSpecifier.getLiteralValue(), newModulePath);
|
|
1019
|
+
moduleSpecifier.setLiteralValue(newModuleSpecifier);
|
|
1020
|
+
if (importSet && newModuleSpecifier.startsWith("internal")) {
|
|
1021
|
+
for (const importName of importDeclaration.getNamedImports().map((imp) => imp.getName())) {
|
|
1022
|
+
importSet.add(`${newModuleSpecifier}:${importName}`);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
for (const exportedDecl of sourceFile.getStatements()) {
|
|
1027
|
+
if (Node.isModifierable(exportedDecl)) {
|
|
1028
|
+
exportedDecl.toggleModifier("declare", false);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
for (const exportDeclaration of sourceFile.getExportDeclarations()) {
|
|
1032
|
+
const moduleSpecifier = exportDeclaration.getModuleSpecifier();
|
|
1033
|
+
if (moduleSpecifier) {
|
|
1034
|
+
const newModuleSpecifier = transformModuleSpecifier(moduleSpecifier.getLiteralValue(), newModulePath);
|
|
1035
|
+
moduleSpecifier.setLiteralValue(newModuleSpecifier);
|
|
1036
|
+
if (importSet && newModuleSpecifier.startsWith("internal")) {
|
|
1037
|
+
for (const exportName of exportDeclaration.getNamedExports().map((exp) => exp.getName())) {
|
|
1038
|
+
importSet.add(`${newModuleSpecifier}:${exportName}`);
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
sourceFile.getDescendantsOfKind(SyntaxKind.ImportType).forEach((node) => {
|
|
1044
|
+
let moduleSpecifier = node.getArgument().getText();
|
|
1045
|
+
if (moduleSpecifier.startsWith('"') && moduleSpecifier.endsWith('"')) {
|
|
1046
|
+
moduleSpecifier = moduleSpecifier.slice(1, -1);
|
|
1047
|
+
}
|
|
1048
|
+
const newModuleSpecifier = transformModuleSpecifier(moduleSpecifier, newModulePath);
|
|
1049
|
+
node.setArgument(newModuleSpecifier);
|
|
1050
|
+
const importName = node.getQualifier()?.getText();
|
|
1051
|
+
if (importSet && newModuleSpecifier.startsWith("internal") && importName) {
|
|
1052
|
+
importSet.add(`${newModuleSpecifier}:${importName}`);
|
|
1053
|
+
}
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
function getPackageName(dir) {
|
|
1057
|
+
const pkg = fs.readFileSync(path.join(dir, "package.json"));
|
|
1058
|
+
const parsed = JSON.parse(pkg.toString());
|
|
1059
|
+
return parsed.name;
|
|
1060
|
+
}
|
|
1061
|
+
function* getTypeFiles(dir) {
|
|
1062
|
+
for (const item of fs.readdirSync(dir)) {
|
|
1063
|
+
const target = path.join(dir, item);
|
|
1064
|
+
if (target.endsWith(".d.ts") && !target.endsWith(".test.d.ts") || target.endsWith(".d.cts") && !target.endsWith(".test.d.cts")) {
|
|
1065
|
+
yield target;
|
|
1066
|
+
} else {
|
|
1067
|
+
const stat = fs.lstatSync(target);
|
|
1068
|
+
if (stat.isDirectory() && item !== "test") {
|
|
1069
|
+
yield* getTypeFiles(target);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
function transformModuleSpecifier(value, filePath) {
|
|
1075
|
+
let moduleSpecifier;
|
|
1076
|
+
if (value.startsWith("@osdk")) {
|
|
1077
|
+
if (value.startsWith("@osdk/gateway/types")) {
|
|
1078
|
+
moduleSpecifier = `internal/${value.replace("@osdk/gateway/types", "@osdk/gateway/public/types")}`;
|
|
1079
|
+
} else {
|
|
1080
|
+
const maybe = value.match(splitExtension);
|
|
1081
|
+
value = maybe ? maybe[1] : value;
|
|
1082
|
+
moduleSpecifier = `internal/${value}`;
|
|
1083
|
+
}
|
|
1084
|
+
} else if (value.startsWith(".")) {
|
|
1085
|
+
const maybe = value.match(splitExtension);
|
|
1086
|
+
value = maybe ? maybe[1] : value;
|
|
1087
|
+
moduleSpecifier = path.join(filePath, "..", value);
|
|
1088
|
+
} else if (KNOWN_EXTERNAL.has(value)) {
|
|
1089
|
+
moduleSpecifier = `internal/${value}`;
|
|
1090
|
+
} else {
|
|
1091
|
+
throw new Error("Failed generated DTS for package, no handling for: " + value);
|
|
1092
|
+
}
|
|
1093
|
+
return withoutTrailingIndex(withoutExtension(moduleSpecifier));
|
|
1094
|
+
}
|
|
1095
|
+
function withoutExtension(value) {
|
|
1096
|
+
return value.replace(".js", "");
|
|
1097
|
+
}
|
|
1022
1098
|
|
|
1023
1099
|
// src/generate/betaClient/bundleDependencies.ts
|
|
1024
1100
|
async function bundleDependencies(dirs, generatedPackageName, generatedFiles, entry) {
|
|
@@ -1027,12 +1103,15 @@ async function bundleDependencies(dirs, generatedPackageName, generatedFiles, en
|
|
|
1027
1103
|
compilerOptions: {
|
|
1028
1104
|
declaration: true,
|
|
1029
1105
|
emitDeclarationOnly: true,
|
|
1030
|
-
outFile: "dist/bundle/index.d.ts"
|
|
1106
|
+
outFile: "dist/bundle/index.d.ts",
|
|
1107
|
+
paths: {
|
|
1108
|
+
"internal/*": ["/internal/*"]
|
|
1109
|
+
}
|
|
1031
1110
|
}
|
|
1032
1111
|
});
|
|
1033
1112
|
const importSet = await copyFiles(project, dirs, generatedPackageName, generatedFiles);
|
|
1034
1113
|
if (entry) {
|
|
1035
|
-
const projectMinifier = new ProjectMinifier(project, importSet
|
|
1114
|
+
const projectMinifier = new ProjectMinifier(project, importSet);
|
|
1036
1115
|
projectMinifier.minifyProject();
|
|
1037
1116
|
}
|
|
1038
1117
|
return outputModule(project);
|
|
@@ -1132,7 +1211,8 @@ async function generatePackageJson(options) {
|
|
|
1132
1211
|
|
|
1133
1212
|
// src/generate/betaClient/generatePackage.ts
|
|
1134
1213
|
var dependencies = {
|
|
1135
|
-
"@osdk/legacy-client": typeof __OSDK_LEGACY_CLIENT_VERSION__ !== "undefined" ? __OSDK_LEGACY_CLIENT_VERSION__ : void 0
|
|
1214
|
+
"@osdk/legacy-client": typeof __OSDK_LEGACY_CLIENT_VERSION__ !== "undefined" ? __OSDK_LEGACY_CLIENT_VERSION__ : void 0,
|
|
1215
|
+
"@osdk/api": typeof __OSDK_API_VERSION__ !== "undefined" ? __OSDK_API_VERSION__ : void 0
|
|
1136
1216
|
};
|
|
1137
1217
|
var betaDependencies = {
|
|
1138
1218
|
"@osdk/client.api": typeof __OSDK_CLIENT_API_VERSION__ !== "undefined" ? __OSDK_CLIENT_API_VERSION__ : void 0,
|
|
@@ -1186,7 +1266,7 @@ async function generatePackage(ontology, options) {
|
|
|
1186
1266
|
let bundleDts = "";
|
|
1187
1267
|
if (nodeModulesPath) {
|
|
1188
1268
|
try {
|
|
1189
|
-
bundleDts = await bundleDependencies(options.beta ? [] : [join(nodeModulesPath, "@osdk", "legacy-client"), join(nodeModulesPath, "@osdk", "api"), join(nodeModulesPath, "@osdk", "gateway")], options.packageName, compilerOutput.files, options.beta ? void 0 : `internal/@osdk/legacy-client/index.ts`);
|
|
1269
|
+
bundleDts = await bundleDependencies(options.beta ? [] : [join(nodeModulesPath, "@osdk", "legacy-client"), join(nodeModulesPath, "@osdk", "api"), join(nodeModulesPath, "@osdk", "gateway"), join(nodeModulesPath, "@osdk", "shared.net"), join(nodeModulesPath, "@osdk", "shared.client")], options.packageName, compilerOutput.files, options.beta ? void 0 : `internal/@osdk/legacy-client/index.ts`);
|
|
1190
1270
|
} catch (e) {
|
|
1191
1271
|
consola2.error("Failed bundling DTS", e);
|
|
1192
1272
|
}
|