@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/build/cjs/index.cjs
CHANGED
|
@@ -15,6 +15,7 @@ var rollup = require('rollup');
|
|
|
15
15
|
var nodePolyfill = require('rollup-plugin-polyfill-node');
|
|
16
16
|
var tsMorph = require('ts-morph');
|
|
17
17
|
var fs = require('fs');
|
|
18
|
+
var utils = require('consola/utils');
|
|
18
19
|
var typescript = require('typescript');
|
|
19
20
|
|
|
20
21
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -586,7 +587,7 @@ function isValidSemver(semverString) {
|
|
|
586
587
|
}
|
|
587
588
|
|
|
588
589
|
// src/utils/UserAgent.ts
|
|
589
|
-
var USER_AGENT = `typescript-sdk-generator/${"1.3.
|
|
590
|
+
var USER_AGENT = `typescript-sdk-generator/${"1.3.14"}`;
|
|
590
591
|
async function createRollupBuild(absolutePackagePath, packageName) {
|
|
591
592
|
const inputPath = `${absolutePackagePath}/${packageName}/index.js`;
|
|
592
593
|
const {
|
|
@@ -629,166 +630,25 @@ async function generateEsmBuild(absolutePackagePath, packageName) {
|
|
|
629
630
|
async function generateBundles(absolutePackagePath, packageName) {
|
|
630
631
|
await Promise.all([generateEsmBuild(absolutePackagePath, packageName)]);
|
|
631
632
|
}
|
|
632
|
-
|
|
633
|
-
// src/generate/betaClient/getModuleSourceFile.ts
|
|
634
|
-
function getModuleSourceFile(project, node) {
|
|
635
|
-
let exportSourceFile;
|
|
636
|
-
try {
|
|
637
|
-
exportSourceFile = project.getSourceFile(`/${node.getLiteralText()}.ts`);
|
|
638
|
-
if (!exportSourceFile) {
|
|
639
|
-
exportSourceFile = project.getSourceFile(`/${node.getLiteralText()}/index.ts`);
|
|
640
|
-
if (!exportSourceFile) {
|
|
641
|
-
return void 0;
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
} catch (e) {
|
|
645
|
-
return void 0;
|
|
646
|
-
}
|
|
647
|
-
return exportSourceFile;
|
|
648
|
-
}
|
|
649
|
-
function withoutTrailingIndex(filePath) {
|
|
650
|
-
return filePath.endsWith("/index") ? filePath.slice(0, -6) : filePath;
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
// src/generate/betaClient/copyFiles.ts
|
|
654
|
-
var KNOWN_EXTERNAL = /* @__PURE__ */ new Set(["geojson"]);
|
|
655
|
-
function removeDts(file) {
|
|
656
|
-
return file.replace(/\.d\.c?ts$/, "");
|
|
657
|
-
}
|
|
658
|
-
async function copyFiles(project, dirs, generatedPackageName, generatedFiles) {
|
|
659
|
-
const importSet = /* @__PURE__ */ new Set();
|
|
660
|
-
for (const [fileName, file] of Object.entries(generatedFiles)) {
|
|
661
|
-
if (!fileName.endsWith(".d.ts") && !fileName.endsWith(".d.cts")) {
|
|
662
|
-
continue;
|
|
663
|
-
}
|
|
664
|
-
const indexOfPackageName = fileName.indexOf(generatedPackageName);
|
|
665
|
-
const tsPath = removeDts(fileName.slice(indexOfPackageName + generatedPackageName.length));
|
|
666
|
-
const newModulePath = `${generatedPackageName}${tsPath}`;
|
|
667
|
-
const sourceFile = project.createSourceFile(newModulePath, file);
|
|
668
|
-
for (const importDeclaration of sourceFile.getImportDeclarations()) {
|
|
669
|
-
const moduleSpecifier = importDeclaration.getModuleSpecifier();
|
|
670
|
-
const newModuleSpecifier = transformModuleSpecifier(moduleSpecifier.getLiteralValue(), newModulePath);
|
|
671
|
-
moduleSpecifier.setLiteralValue(newModuleSpecifier);
|
|
672
|
-
if (newModuleSpecifier.startsWith("internal")) {
|
|
673
|
-
for (const importName of importDeclaration.getNamedImports().map((imp) => imp.getName())) {
|
|
674
|
-
importSet.add(importName);
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
for (const exportedDecl of sourceFile.getStatements()) {
|
|
679
|
-
if (tsMorph.Node.isModifierable(exportedDecl)) {
|
|
680
|
-
exportedDecl.toggleModifier("declare", false);
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
for (const exportDeclaration of sourceFile.getExportDeclarations()) {
|
|
684
|
-
const moduleSpecifier = exportDeclaration.getModuleSpecifier();
|
|
685
|
-
if (moduleSpecifier) {
|
|
686
|
-
const newModuleSpecifier = transformModuleSpecifier(moduleSpecifier.getLiteralValue(), newModulePath);
|
|
687
|
-
moduleSpecifier.setLiteralValue(newModuleSpecifier);
|
|
688
|
-
if (newModuleSpecifier.startsWith("internal")) {
|
|
689
|
-
for (const exportName of exportDeclaration.getNamedExports().map((exp) => exp.getName())) {
|
|
690
|
-
importSet.add(exportName);
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
for (const dir of dirs) {
|
|
697
|
-
const buildDirsToTry = ["build/cjs", "build/esm"];
|
|
698
|
-
const packageName = getPackageName(dir);
|
|
699
|
-
const relativeBuildDir = buildDirsToTry.find((buildDir) => {
|
|
700
|
-
return ["d.ts", "d.cts", "d.mts"].some((ext) => {
|
|
701
|
-
try {
|
|
702
|
-
fs__namespace.statSync(path__namespace.join(dir, buildDir, `index.${ext}`));
|
|
703
|
-
return true;
|
|
704
|
-
} catch (e) {
|
|
705
|
-
return false;
|
|
706
|
-
}
|
|
707
|
-
});
|
|
708
|
-
});
|
|
709
|
-
if (!relativeBuildDir) {
|
|
710
|
-
throw new Error("Couldn't find the right build dir");
|
|
711
|
-
}
|
|
712
|
-
for (const file of getTypeFiles(path__namespace.join(dir, relativeBuildDir))) {
|
|
713
|
-
const absoluteBuildDir = path__namespace.join(dir, relativeBuildDir);
|
|
714
|
-
const tsPath = removeDts(path__namespace.relative(absoluteBuildDir, file));
|
|
715
|
-
const newModulePath = `internal/${packageName}/${tsPath}`;
|
|
716
|
-
const fileContents = fs__namespace.readFileSync(file).toString();
|
|
717
|
-
const sourceFile = project.createSourceFile(`${newModulePath}.ts`, fileContents, {
|
|
718
|
-
overwrite: true
|
|
719
|
-
});
|
|
720
|
-
for (const importDeclaration of sourceFile.getImportDeclarations()) {
|
|
721
|
-
const moduleSpecifier = importDeclaration.getModuleSpecifier();
|
|
722
|
-
const newModuleSpecifier = transformModuleSpecifier(moduleSpecifier.getLiteralValue(), newModulePath);
|
|
723
|
-
moduleSpecifier.setLiteralValue(newModuleSpecifier);
|
|
724
|
-
}
|
|
725
|
-
for (const exportedDecl of sourceFile.getStatements()) {
|
|
726
|
-
if (tsMorph.Node.isModifierable(exportedDecl)) {
|
|
727
|
-
exportedDecl.toggleModifier("declare", false);
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
for (const exportDeclaration of sourceFile.getExportDeclarations()) {
|
|
731
|
-
const moduleSpecifier = exportDeclaration.getModuleSpecifier();
|
|
732
|
-
if (moduleSpecifier) {
|
|
733
|
-
const newModuleSpecifier = transformModuleSpecifier(moduleSpecifier.getLiteralValue(), newModulePath);
|
|
734
|
-
moduleSpecifier.setLiteralValue(withoutTrailingIndex(newModuleSpecifier));
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
return importSet;
|
|
740
|
-
}
|
|
741
|
-
function getPackageName(dir) {
|
|
742
|
-
const pkg = fs__namespace.readFileSync(path__namespace.join(dir, "package.json"));
|
|
743
|
-
const parsed = JSON.parse(pkg.toString());
|
|
744
|
-
return parsed.name;
|
|
745
|
-
}
|
|
746
|
-
function* getTypeFiles(dir) {
|
|
747
|
-
for (const item of fs__namespace.readdirSync(dir)) {
|
|
748
|
-
const target = path__namespace.join(dir, item);
|
|
749
|
-
if (target.endsWith(".d.ts") && !target.endsWith(".test.d.ts") || target.endsWith(".d.cts") && !target.endsWith(".test.d.cts")) {
|
|
750
|
-
yield target;
|
|
751
|
-
} else {
|
|
752
|
-
const stat = fs__namespace.lstatSync(target);
|
|
753
|
-
if (stat.isDirectory() && item !== "test") {
|
|
754
|
-
yield* getTypeFiles(target);
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
function transformModuleSpecifier(value, filePath) {
|
|
760
|
-
let moduleSpecifier;
|
|
761
|
-
if (value.startsWith("@osdk")) {
|
|
762
|
-
if (value.startsWith("@osdk/gateway/types")) {
|
|
763
|
-
moduleSpecifier = `internal/${value.replace("@osdk/gateway/types", "@osdk/gateway/public/types")}`;
|
|
764
|
-
} else {
|
|
765
|
-
moduleSpecifier = `internal/${value}`;
|
|
766
|
-
}
|
|
767
|
-
} else if (value.startsWith(".")) {
|
|
768
|
-
moduleSpecifier = path__namespace.join(filePath, "..", value);
|
|
769
|
-
} else if (KNOWN_EXTERNAL.has(value)) {
|
|
770
|
-
moduleSpecifier = `internal/${value}`;
|
|
771
|
-
} else {
|
|
772
|
-
throw new Error("Failed generated DTS for package, no handling for: " + value);
|
|
773
|
-
}
|
|
774
|
-
return withoutTrailingIndex(withoutExtension(moduleSpecifier));
|
|
775
|
-
}
|
|
776
|
-
function withoutExtension(value) {
|
|
777
|
-
return value.replace(".js", "");
|
|
778
|
-
}
|
|
633
|
+
var DEBUG = false;
|
|
779
634
|
var ProjectMinifier = class {
|
|
780
635
|
nodesToKeep = {};
|
|
781
636
|
visitedImports = {};
|
|
782
637
|
dependentExport = {};
|
|
783
638
|
stack = [];
|
|
784
|
-
constructor(project, startingImportSet
|
|
639
|
+
constructor(project, startingImportSet) {
|
|
785
640
|
this.project = project;
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
641
|
+
const filesToImports = {};
|
|
642
|
+
for (const importSet of startingImportSet) {
|
|
643
|
+
const [file, importString] = importSet.split(":");
|
|
644
|
+
if (!filesToImports[file]) {
|
|
645
|
+
filesToImports[file] = /* @__PURE__ */ new Set();
|
|
646
|
+
}
|
|
647
|
+
filesToImports[file].add(importString);
|
|
648
|
+
}
|
|
649
|
+
for (const [file, imports] of Object.entries(filesToImports)) {
|
|
650
|
+
this.pushNextVisit(getModuleSourceFile(project, file), imports, "constructor");
|
|
651
|
+
}
|
|
792
652
|
}
|
|
793
653
|
shouldContinueVisiting() {
|
|
794
654
|
return this.stack.length > 0;
|
|
@@ -799,7 +659,8 @@ var ProjectMinifier = class {
|
|
|
799
659
|
}
|
|
800
660
|
return this.stack.pop();
|
|
801
661
|
}
|
|
802
|
-
pushNextVisit(sourceFile, imports) {
|
|
662
|
+
pushNextVisit(sourceFile, imports, source) {
|
|
663
|
+
if (imports.size === 0) return;
|
|
803
664
|
this.stack.push({
|
|
804
665
|
sourceFile,
|
|
805
666
|
imports
|
|
@@ -815,6 +676,8 @@ var ProjectMinifier = class {
|
|
|
815
676
|
if (!this.visitedImports[filePath].has(importToCheck)) {
|
|
816
677
|
shouldSkipCheck = false;
|
|
817
678
|
this.visitedImports[filePath].add(importToCheck);
|
|
679
|
+
} else {
|
|
680
|
+
traversalStep.imports.delete(importToCheck);
|
|
818
681
|
}
|
|
819
682
|
}
|
|
820
683
|
return shouldSkipCheck;
|
|
@@ -834,15 +697,23 @@ var ProjectMinifier = class {
|
|
|
834
697
|
const identifiersToResolve = /* @__PURE__ */ new Set();
|
|
835
698
|
const sourceFile = visitImports.sourceFile;
|
|
836
699
|
const moduleName = getModuleFromFileName(sourceFile);
|
|
837
|
-
const
|
|
700
|
+
const nodesToKeepForThisModule = this.getNodesToKeepForModule(moduleName);
|
|
838
701
|
for (const [key, declarations] of sourceFile.getExportedDeclarations()) {
|
|
702
|
+
if (declarations.length === 0 && DEBUG) {
|
|
703
|
+
console.log(`Possible issue for sdk with slate: can't find declaration for ${key} from ${logNode(sourceFile)}`);
|
|
704
|
+
}
|
|
839
705
|
if (!visitImports.imports.has(key)) {
|
|
840
706
|
continue;
|
|
841
707
|
}
|
|
842
708
|
this.visitDependentExports(moduleName);
|
|
843
|
-
this.visitDeclaration(declarations,
|
|
709
|
+
this.visitDeclaration(declarations, nodesToKeepForThisModule, identifiersToResolve);
|
|
844
710
|
}
|
|
845
711
|
for (const declaration of sourceFile.getExportDeclarations()) {
|
|
712
|
+
let deleteFromSet2 = function(set, toDelete) {
|
|
713
|
+
for (const d of toDelete) {
|
|
714
|
+
set.delete(d);
|
|
715
|
+
}
|
|
716
|
+
};
|
|
846
717
|
const moduleSpecifier = declaration.getModuleSpecifier();
|
|
847
718
|
if (!moduleSpecifier) {
|
|
848
719
|
continue;
|
|
@@ -860,20 +731,28 @@ var ProjectMinifier = class {
|
|
|
860
731
|
const nodesToKeepForModule = this.getNodesToKeepForModule(getModuleFromFileName(exportSourceFile));
|
|
861
732
|
nodesToKeepForModule.add(exportSourceFile);
|
|
862
733
|
const importsFromNamespace = new Set(exportSourceFile.getExportedDeclarations().keys());
|
|
863
|
-
this.pushNextVisit(exportSourceFile, importsFromNamespace);
|
|
734
|
+
this.pushNextVisit(exportSourceFile, importsFromNamespace, "minifyProjectA");
|
|
864
735
|
}
|
|
865
736
|
}
|
|
866
737
|
}
|
|
867
738
|
const namedExports = declaration.getNamedExports();
|
|
868
739
|
if (namedExports.length === 0) {
|
|
869
|
-
|
|
740
|
+
const depExportNames = new Set(exportSourceFile.getExportSymbols().map((s) => s.getName()).filter((s) => visitImports.imports.has(s)));
|
|
741
|
+
deleteFromSet2(visitImports.imports, depExportNames);
|
|
742
|
+
this.pushNextVisit(exportSourceFile, depExportNames, "minifyProjectB");
|
|
870
743
|
if (!this.dependentExport[literalText]) {
|
|
871
744
|
this.dependentExport[literalText] = /* @__PURE__ */ new Set();
|
|
872
745
|
}
|
|
873
746
|
this.dependentExport[literalText].add(declaration);
|
|
874
747
|
continue;
|
|
875
748
|
}
|
|
876
|
-
this.visitNamedExports(namedExports, visitImports,
|
|
749
|
+
this.visitNamedExports(namedExports, visitImports, nodesToKeepForThisModule, exportSourceFile);
|
|
750
|
+
for (const n of namedExports) {
|
|
751
|
+
if (visitImports.imports.has(n.getName())) {
|
|
752
|
+
nodesToKeepForThisModule.add(n);
|
|
753
|
+
visitImports.imports.delete(n.getName());
|
|
754
|
+
}
|
|
755
|
+
}
|
|
877
756
|
}
|
|
878
757
|
for (const declaration of sourceFile.getImportDeclarations()) {
|
|
879
758
|
const namedImports = declaration.getNamedImports();
|
|
@@ -894,12 +773,21 @@ var ProjectMinifier = class {
|
|
|
894
773
|
this.getNodesToKeepForModule(moduleSpecifier.getLiteralText()).add(decl);
|
|
895
774
|
});
|
|
896
775
|
this.getNodesToKeepForModule(moduleSpecifier.getLiteralText()).add(sourceFile);
|
|
897
|
-
this.pushNextVisit(importSourceFile, importsFromNamespace);
|
|
776
|
+
this.pushNextVisit(importSourceFile, importsFromNamespace, "minifyProjectC");
|
|
898
777
|
}
|
|
899
778
|
continue;
|
|
900
779
|
}
|
|
901
780
|
this.visitNamedImports(namedImports, identifiersToResolve, moduleName, declaration, importSourceFile);
|
|
902
781
|
}
|
|
782
|
+
sourceFile.getDescendantsOfKind(tsMorph.SyntaxKind.ImportType).forEach((node) => {
|
|
783
|
+
const moduleSpecifier = node.getArgument().getText().slice(1, -1);
|
|
784
|
+
const importSourceFile = getModuleSourceFile(this.project, moduleSpecifier);
|
|
785
|
+
const qualifier = node.getQualifier();
|
|
786
|
+
const qualifierSymbol = qualifier?.getSymbol();
|
|
787
|
+
if (qualifier && qualifierSymbol && importSourceFile && identifiersToResolve.has(qualifierSymbol)) {
|
|
788
|
+
this.pushNextVisit(importSourceFile, /* @__PURE__ */ new Set([qualifier.getText()]), "dynamic imports");
|
|
789
|
+
}
|
|
790
|
+
});
|
|
903
791
|
}
|
|
904
792
|
this.deleteUnused();
|
|
905
793
|
}
|
|
@@ -917,7 +805,7 @@ var ProjectMinifier = class {
|
|
|
917
805
|
this.getNodesToKeepForModule(moduleName).add(declaration);
|
|
918
806
|
}
|
|
919
807
|
}
|
|
920
|
-
this.pushNextVisit(importSourceFile, importsToVisit);
|
|
808
|
+
this.pushNextVisit(importSourceFile, importsToVisit, "visitNamedImports");
|
|
921
809
|
}
|
|
922
810
|
// For each named export if it is something that we need, we keep the export
|
|
923
811
|
// And visit the module it is exported from
|
|
@@ -938,33 +826,33 @@ var ProjectMinifier = class {
|
|
|
938
826
|
nodeSet.add(ancestor);
|
|
939
827
|
}
|
|
940
828
|
}
|
|
941
|
-
this.pushNextVisit(exportSourceFile, exportsToVisit);
|
|
829
|
+
this.pushNextVisit(exportSourceFile, exportsToVisit, "visitNamedExports");
|
|
942
830
|
}
|
|
943
831
|
// Traverse the declaration and it's dependent symbols
|
|
944
|
-
visitDeclaration(declarations,
|
|
945
|
-
const declarationStack = declarations;
|
|
832
|
+
visitDeclaration(declarations, nodesToKeep, identifiersToResolve) {
|
|
833
|
+
const declarationStack = [...declarations];
|
|
946
834
|
while (declarationStack.length > 0) {
|
|
947
835
|
const currentDeclaration = declarationStack.pop();
|
|
948
|
-
if (
|
|
836
|
+
if (nodesToKeep.has(currentDeclaration)) {
|
|
949
837
|
continue;
|
|
950
838
|
}
|
|
951
|
-
|
|
839
|
+
nodesToKeep.add(currentDeclaration);
|
|
952
840
|
for (const ancestor of currentDeclaration.getAncestors()) {
|
|
953
|
-
|
|
841
|
+
nodesToKeep.add(ancestor);
|
|
954
842
|
}
|
|
955
843
|
for (const child of currentDeclaration.getDescendantsOfKind(tsMorph.SyntaxKind.Identifier)) {
|
|
956
844
|
const symbol = child.getSymbol();
|
|
957
|
-
if (!symbol ||
|
|
845
|
+
if (!symbol || identifiersToResolve.has(symbol)) {
|
|
958
846
|
continue;
|
|
959
847
|
}
|
|
960
|
-
|
|
848
|
+
identifiersToResolve.add(symbol);
|
|
961
849
|
for (const symbolDeclaration of symbol.getDeclarations()) {
|
|
962
850
|
if (tsMorph.Node.isImportDeclaration(symbolDeclaration)) {
|
|
963
851
|
const importSourceFile = getModuleSourceFile(this.project, symbolDeclaration.getModuleSpecifier());
|
|
964
852
|
if (!importSourceFile) {
|
|
965
853
|
continue;
|
|
966
854
|
}
|
|
967
|
-
this.pushNextVisit(importSourceFile, new Set(symbol.getName()));
|
|
855
|
+
this.pushNextVisit(importSourceFile, new Set(symbol.getName()), "visitDeclaration");
|
|
968
856
|
} else {
|
|
969
857
|
declarationStack.push(symbolDeclaration);
|
|
970
858
|
}
|
|
@@ -1004,7 +892,17 @@ var ProjectMinifier = class {
|
|
|
1004
892
|
exportDeclaration.remove();
|
|
1005
893
|
continue;
|
|
1006
894
|
}
|
|
1007
|
-
for (const namedExport of exportDeclaration.getNamedExports()) {
|
|
895
|
+
perNamedExport: for (const namedExport of exportDeclaration.getNamedExports()) {
|
|
896
|
+
for (const n of nodesToKeepForTargetModule) {
|
|
897
|
+
if (tsMorph.Node.isExportable(n) && n.getSourceFile().getFilePath().startsWith("/internal")) {
|
|
898
|
+
if (n.getSymbol()?.getName() === namedExport.getName()) {
|
|
899
|
+
continue perNamedExport;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
if (nodesToKeepForModule.has(namedExport)) {
|
|
904
|
+
continue perNamedExport;
|
|
905
|
+
}
|
|
1008
906
|
if (!nodesToKeepForTargetModule.has(namedExport)) {
|
|
1009
907
|
namedExport.remove();
|
|
1010
908
|
}
|
|
@@ -1047,6 +945,184 @@ var ProjectMinifier = class {
|
|
|
1047
945
|
function getModuleFromFileName(sourceFile) {
|
|
1048
946
|
return sourceFile.getFilePath().replace("/", "").replace(".ts", "").replace("/index", "");
|
|
1049
947
|
}
|
|
948
|
+
function logFilename(node) {
|
|
949
|
+
if (typeof node === "string") {
|
|
950
|
+
return utils.colorize("yellow", node);
|
|
951
|
+
}
|
|
952
|
+
return utils.colorize("yellow", `${node.getSourceFile().getFilePath()}:${node.getStartLineNumber()}`);
|
|
953
|
+
}
|
|
954
|
+
function logNode(node, {
|
|
955
|
+
ancestors,
|
|
956
|
+
text
|
|
957
|
+
} = {
|
|
958
|
+
ancestors: false,
|
|
959
|
+
text: true
|
|
960
|
+
}) {
|
|
961
|
+
if (tsMorph.Node.isSourceFile(node)) {
|
|
962
|
+
return `${utils.colorize("blue", "SourceFile[")}${logFilename(node)}${utils.colorize("blue", "]")}`;
|
|
963
|
+
}
|
|
964
|
+
return `${utils.colorize("blue", "Node[")}${logFilename(node)}: ${utils.colorize("gray", node.getKindName())}${ancestors ? `:${node.getAncestors().map((n) => n.getKindName()).join(":")}` : ""}${text ? `:${logJustNodeText(node)}` : ""}${utils.colorize("blue", "]")}`;
|
|
965
|
+
}
|
|
966
|
+
function logJustNodeText(node, {
|
|
967
|
+
maxLength
|
|
968
|
+
} = {
|
|
969
|
+
maxLength: 50
|
|
970
|
+
}) {
|
|
971
|
+
const a = node.getText().replace(/\n/g, "\\n");
|
|
972
|
+
if (a.length <= maxLength) return `\`${a}\``;
|
|
973
|
+
return `\`${a.slice(0, maxLength)}\`...`;
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
// src/generate/betaClient/getModuleSourceFile.ts
|
|
977
|
+
var splitExtension = /^(.*)(\.[cm]?js)$/;
|
|
978
|
+
function getModuleSourceFile(project, node) {
|
|
979
|
+
let exportSourceFile;
|
|
980
|
+
const literalText = typeof node === "string" ? node : node.getLiteralText();
|
|
981
|
+
const withoutExtension2 = literalText.match(splitExtension)?.[1] ?? literalText;
|
|
982
|
+
try {
|
|
983
|
+
exportSourceFile = project.getSourceFile(`/${withoutExtension2}.ts`);
|
|
984
|
+
if (!exportSourceFile) {
|
|
985
|
+
exportSourceFile = project.getSourceFile(`/${withoutExtension2}/index.ts`);
|
|
986
|
+
if (DEBUG && !exportSourceFile) ;
|
|
987
|
+
}
|
|
988
|
+
} catch (e) {
|
|
989
|
+
console.log(e);
|
|
990
|
+
return void 0;
|
|
991
|
+
}
|
|
992
|
+
return exportSourceFile;
|
|
993
|
+
}
|
|
994
|
+
function withoutTrailingIndex(filePath) {
|
|
995
|
+
return filePath.endsWith("/index") ? filePath.slice(0, -6) : filePath;
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
// src/generate/betaClient/copyFiles.ts
|
|
999
|
+
var KNOWN_EXTERNAL = /* @__PURE__ */ new Set(["geojson"]);
|
|
1000
|
+
function removeDts(file) {
|
|
1001
|
+
return file.replace(/\.d\.c?ts$/, "");
|
|
1002
|
+
}
|
|
1003
|
+
async function copyFiles(project, dirs, generatedPackageName, generatedFiles) {
|
|
1004
|
+
const importSet = /* @__PURE__ */ new Set();
|
|
1005
|
+
for (const [fileName, file] of Object.entries(generatedFiles)) {
|
|
1006
|
+
if (!fileName.endsWith(".d.ts") && !fileName.endsWith(".d.cts")) {
|
|
1007
|
+
continue;
|
|
1008
|
+
}
|
|
1009
|
+
const indexOfPackageName = fileName.indexOf(generatedPackageName);
|
|
1010
|
+
const tsPath = removeDts(fileName.slice(indexOfPackageName + generatedPackageName.length));
|
|
1011
|
+
const newModulePath = `${generatedPackageName}${tsPath}`;
|
|
1012
|
+
const sourceFile = project.createSourceFile(newModulePath, file);
|
|
1013
|
+
remapImportsExports(sourceFile, newModulePath, importSet);
|
|
1014
|
+
}
|
|
1015
|
+
for (const dir of dirs) {
|
|
1016
|
+
const buildDirsToTry = [path__namespace.join(dir, "build", "cjs"), path__namespace.join(dir, "build", "esm"), dir];
|
|
1017
|
+
const packageName = getPackageName(dir);
|
|
1018
|
+
const absoluteBuildDir = buildDirsToTry.find((buildDir) => {
|
|
1019
|
+
return ["d.ts", "d.cts", "d.mts"].some((ext) => {
|
|
1020
|
+
try {
|
|
1021
|
+
fs__namespace.statSync(path__namespace.join(buildDir, `index.${ext}`));
|
|
1022
|
+
return true;
|
|
1023
|
+
} catch (e) {
|
|
1024
|
+
return false;
|
|
1025
|
+
}
|
|
1026
|
+
});
|
|
1027
|
+
});
|
|
1028
|
+
if (!absoluteBuildDir) {
|
|
1029
|
+
throw new Error("Couldn't find the right build dir");
|
|
1030
|
+
}
|
|
1031
|
+
for (const file of getTypeFiles(absoluteBuildDir)) {
|
|
1032
|
+
const tsPath = removeDts(path__namespace.relative(absoluteBuildDir, file));
|
|
1033
|
+
const newModulePath = `internal/${packageName}/${tsPath}`;
|
|
1034
|
+
const fileContents = fs__namespace.readFileSync(file).toString();
|
|
1035
|
+
const sourceFile = project.createSourceFile(`${newModulePath}.ts`, fileContents, {
|
|
1036
|
+
overwrite: true
|
|
1037
|
+
});
|
|
1038
|
+
remapImportsExports(sourceFile, newModulePath, void 0);
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
return importSet;
|
|
1042
|
+
}
|
|
1043
|
+
function remapImportsExports(sourceFile, newModulePath, importSet) {
|
|
1044
|
+
for (const importDeclaration of sourceFile.getImportDeclarations()) {
|
|
1045
|
+
const moduleSpecifier = importDeclaration.getModuleSpecifier();
|
|
1046
|
+
const newModuleSpecifier = transformModuleSpecifier(moduleSpecifier.getLiteralValue(), newModulePath);
|
|
1047
|
+
moduleSpecifier.setLiteralValue(newModuleSpecifier);
|
|
1048
|
+
if (importSet && newModuleSpecifier.startsWith("internal")) {
|
|
1049
|
+
for (const importName of importDeclaration.getNamedImports().map((imp) => imp.getName())) {
|
|
1050
|
+
importSet.add(`${newModuleSpecifier}:${importName}`);
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
for (const exportedDecl of sourceFile.getStatements()) {
|
|
1055
|
+
if (tsMorph.Node.isModifierable(exportedDecl)) {
|
|
1056
|
+
exportedDecl.toggleModifier("declare", false);
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
for (const exportDeclaration of sourceFile.getExportDeclarations()) {
|
|
1060
|
+
const moduleSpecifier = exportDeclaration.getModuleSpecifier();
|
|
1061
|
+
if (moduleSpecifier) {
|
|
1062
|
+
const newModuleSpecifier = transformModuleSpecifier(moduleSpecifier.getLiteralValue(), newModulePath);
|
|
1063
|
+
moduleSpecifier.setLiteralValue(newModuleSpecifier);
|
|
1064
|
+
if (importSet && newModuleSpecifier.startsWith("internal")) {
|
|
1065
|
+
for (const exportName of exportDeclaration.getNamedExports().map((exp) => exp.getName())) {
|
|
1066
|
+
importSet.add(`${newModuleSpecifier}:${exportName}`);
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
sourceFile.getDescendantsOfKind(tsMorph.SyntaxKind.ImportType).forEach((node) => {
|
|
1072
|
+
let moduleSpecifier = node.getArgument().getText();
|
|
1073
|
+
if (moduleSpecifier.startsWith('"') && moduleSpecifier.endsWith('"')) {
|
|
1074
|
+
moduleSpecifier = moduleSpecifier.slice(1, -1);
|
|
1075
|
+
}
|
|
1076
|
+
const newModuleSpecifier = transformModuleSpecifier(moduleSpecifier, newModulePath);
|
|
1077
|
+
node.setArgument(newModuleSpecifier);
|
|
1078
|
+
const importName = node.getQualifier()?.getText();
|
|
1079
|
+
if (importSet && newModuleSpecifier.startsWith("internal") && importName) {
|
|
1080
|
+
importSet.add(`${newModuleSpecifier}:${importName}`);
|
|
1081
|
+
}
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
function getPackageName(dir) {
|
|
1085
|
+
const pkg = fs__namespace.readFileSync(path__namespace.join(dir, "package.json"));
|
|
1086
|
+
const parsed = JSON.parse(pkg.toString());
|
|
1087
|
+
return parsed.name;
|
|
1088
|
+
}
|
|
1089
|
+
function* getTypeFiles(dir) {
|
|
1090
|
+
for (const item of fs__namespace.readdirSync(dir)) {
|
|
1091
|
+
const target = path__namespace.join(dir, item);
|
|
1092
|
+
if (target.endsWith(".d.ts") && !target.endsWith(".test.d.ts") || target.endsWith(".d.cts") && !target.endsWith(".test.d.cts")) {
|
|
1093
|
+
yield target;
|
|
1094
|
+
} else {
|
|
1095
|
+
const stat = fs__namespace.lstatSync(target);
|
|
1096
|
+
if (stat.isDirectory() && item !== "test") {
|
|
1097
|
+
yield* getTypeFiles(target);
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
function transformModuleSpecifier(value, filePath) {
|
|
1103
|
+
let moduleSpecifier;
|
|
1104
|
+
if (value.startsWith("@osdk")) {
|
|
1105
|
+
if (value.startsWith("@osdk/gateway/types")) {
|
|
1106
|
+
moduleSpecifier = `internal/${value.replace("@osdk/gateway/types", "@osdk/gateway/public/types")}`;
|
|
1107
|
+
} else {
|
|
1108
|
+
const maybe = value.match(splitExtension);
|
|
1109
|
+
value = maybe ? maybe[1] : value;
|
|
1110
|
+
moduleSpecifier = `internal/${value}`;
|
|
1111
|
+
}
|
|
1112
|
+
} else if (value.startsWith(".")) {
|
|
1113
|
+
const maybe = value.match(splitExtension);
|
|
1114
|
+
value = maybe ? maybe[1] : value;
|
|
1115
|
+
moduleSpecifier = path__namespace.join(filePath, "..", value);
|
|
1116
|
+
} else if (KNOWN_EXTERNAL.has(value)) {
|
|
1117
|
+
moduleSpecifier = `internal/${value}`;
|
|
1118
|
+
} else {
|
|
1119
|
+
throw new Error("Failed generated DTS for package, no handling for: " + value);
|
|
1120
|
+
}
|
|
1121
|
+
return withoutTrailingIndex(withoutExtension(moduleSpecifier));
|
|
1122
|
+
}
|
|
1123
|
+
function withoutExtension(value) {
|
|
1124
|
+
return value.replace(".js", "");
|
|
1125
|
+
}
|
|
1050
1126
|
|
|
1051
1127
|
// src/generate/betaClient/bundleDependencies.ts
|
|
1052
1128
|
async function bundleDependencies(dirs, generatedPackageName, generatedFiles, entry) {
|
|
@@ -1055,12 +1131,15 @@ async function bundleDependencies(dirs, generatedPackageName, generatedFiles, en
|
|
|
1055
1131
|
compilerOptions: {
|
|
1056
1132
|
declaration: true,
|
|
1057
1133
|
emitDeclarationOnly: true,
|
|
1058
|
-
outFile: "dist/bundle/index.d.ts"
|
|
1134
|
+
outFile: "dist/bundle/index.d.ts",
|
|
1135
|
+
paths: {
|
|
1136
|
+
"internal/*": ["/internal/*"]
|
|
1137
|
+
}
|
|
1059
1138
|
}
|
|
1060
1139
|
});
|
|
1061
1140
|
const importSet = await copyFiles(project, dirs, generatedPackageName, generatedFiles);
|
|
1062
1141
|
if (entry) {
|
|
1063
|
-
const projectMinifier = new ProjectMinifier(project, importSet
|
|
1142
|
+
const projectMinifier = new ProjectMinifier(project, importSet);
|
|
1064
1143
|
projectMinifier.minifyProject();
|
|
1065
1144
|
}
|
|
1066
1145
|
return outputModule(project);
|
|
@@ -1160,7 +1239,8 @@ async function generatePackageJson(options) {
|
|
|
1160
1239
|
|
|
1161
1240
|
// src/generate/betaClient/generatePackage.ts
|
|
1162
1241
|
var dependencies = {
|
|
1163
|
-
"@osdk/legacy-client": typeof __OSDK_LEGACY_CLIENT_VERSION__ !== "undefined" ? __OSDK_LEGACY_CLIENT_VERSION__ : void 0
|
|
1242
|
+
"@osdk/legacy-client": typeof __OSDK_LEGACY_CLIENT_VERSION__ !== "undefined" ? __OSDK_LEGACY_CLIENT_VERSION__ : void 0,
|
|
1243
|
+
"@osdk/api": typeof __OSDK_API_VERSION__ !== "undefined" ? __OSDK_API_VERSION__ : void 0
|
|
1164
1244
|
};
|
|
1165
1245
|
var betaDependencies = {
|
|
1166
1246
|
"@osdk/client.api": typeof __OSDK_CLIENT_API_VERSION__ !== "undefined" ? __OSDK_CLIENT_API_VERSION__ : void 0,
|
|
@@ -1214,7 +1294,7 @@ async function generatePackage(ontology, options) {
|
|
|
1214
1294
|
let bundleDts = "";
|
|
1215
1295
|
if (nodeModulesPath) {
|
|
1216
1296
|
try {
|
|
1217
|
-
bundleDts = await bundleDependencies(options.beta ? [] : [path.join(nodeModulesPath, "@osdk", "legacy-client"), path.join(nodeModulesPath, "@osdk", "api"), path.join(nodeModulesPath, "@osdk", "gateway")], options.packageName, compilerOutput.files, options.beta ? void 0 : `internal/@osdk/legacy-client/index.ts`);
|
|
1297
|
+
bundleDts = await bundleDependencies(options.beta ? [] : [path.join(nodeModulesPath, "@osdk", "legacy-client"), path.join(nodeModulesPath, "@osdk", "api"), path.join(nodeModulesPath, "@osdk", "gateway"), path.join(nodeModulesPath, "@osdk", "shared.net"), path.join(nodeModulesPath, "@osdk", "shared.client")], options.packageName, compilerOutput.files, options.beta ? void 0 : `internal/@osdk/legacy-client/index.ts`);
|
|
1218
1298
|
} catch (e) {
|
|
1219
1299
|
consola2.error("Failed bundling DTS", e);
|
|
1220
1300
|
}
|