Skip to content

Commit

Permalink
WIP: Removes per-module TypeScript definitions that supported individ…
Browse files Browse the repository at this point in the history
…ual module imports
  • Loading branch information
sanjeetsuhag committed Oct 28, 2022
1 parent 11deab0 commit 055e753
Showing 1 changed file with 2 additions and 73 deletions.
75 changes: 2 additions & 73 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
/*eslint-env node*/
import { writeFileSync, copyFileSync, readFileSync, existsSync } from "fs";
import { readFile, writeFile } from "fs/promises";
import {
join,
basename,
relative,
extname,
resolve,
posix,
dirname,
} from "path";
import { join, basename, resolve, posix, dirname } from "path";
import { exec, execSync } from "child_process";
import { createHash } from "crypto";
import { gzipSync } from "zlib";
Expand All @@ -22,7 +14,7 @@ import gulpTap from "gulp-tap";
import gulpZip from "gulp-zip";
import gulpRename from "gulp-rename";
import gulpReplace from "gulp-replace";
import { globby, globbySync } from "globby";
import { globby } from "globby";
import open from "open";
import rimraf from "rimraf";
import mkdirp from "mkdirp";
Expand Down Expand Up @@ -89,20 +81,6 @@ const sourceFiles = [
"!Source/ThirdParty/_*",
];

const relativeWorkspaceSourceFiles = {
engine: [
"packages/engine/Source/**/*.js",
"!packages/engine/Source/*.js",
"!packages/engine/Source/Workers/**",
"!packages/engine/Source/WorkersES6/**",
"packages/engine/Source/WorkersES6/createTaskProcessorWorker.js",
"!packages/engine/Source/ThirdParty/Workers/**",
"!packages/engine/Source/ThirdParty/google-earth-dbroot-parser.js",
"!packages/engine/Source/ThirdParty/_*",
],
widgets: ["packages/widgets/Source/**/*.js"],
};

const workerSourceFiles = ["packages/engine/Source/WorkersES6/**"];
const watchedSpecFiles = [
"Specs/**/*Spec.js",
Expand Down Expand Up @@ -1915,36 +1893,6 @@ ${source}
`;

// Map individual modules back to their source file so that TS still works
// when importing individual files instead of the entire cesium module.

globbySync(relativeWorkspaceSourceFiles[`engine`]).forEach(function (file) {
file = relative("packages/engine/Source", file);

let moduleId = file;
moduleId = filePathToModuleId(moduleId);

const assignmentName = basename(file, extname(file));

if (publicModules.has(assignmentName)) {
publicModules.delete(assignmentName);
source += `declare module "${scope}/packages/engine/Source/${moduleId}" { import { ${assignmentName} } from '@${scope}/engine'; export default ${assignmentName}; }\n`;
}
});

globbySync(relativeWorkspaceSourceFiles[`widgets`]).forEach(function (file) {
file = relative("packages/widgets/Source", file);

let moduleId = file;
moduleId = filePathToModuleId(moduleId);

const assignmentName = basename(file, extname(file));
if (publicModules.has(assignmentName)) {
publicModules.delete(assignmentName);
source += `declare module "${scope}/packages/widgets/Source/${moduleId}" { import { ${assignmentName} } from '@${scope}/widgets'; export default ${assignmentName}; }\n`;
}
});

// Write the final source file back out
writeFileSync("Source/Cesium.d.ts", source);

Expand All @@ -1958,21 +1906,6 @@ ${source}
stdio: "inherit",
});

// Below is a sanity check to make sure we didn't leave anything out that
// we don't already know about

// Intentionally ignored nested items
publicModules.delete("KmlFeatureData");
publicModules.delete("MaterialAppearance");

if (publicModules.size !== 0) {
throw new Error(
`Unexpected unexposed modules: ${Array.from(publicModules.values()).join(
", "
)}`
);
}

return Promise.resolve();
}

Expand Down Expand Up @@ -2276,7 +2209,3 @@ async function buildCesiumViewer() {

return streamToPromise(stream.pipe(gulp.dest(cesiumViewerOutputDirectory)));
}

function filePathToModuleId(moduleId) {
return moduleId.substring(0, moduleId.lastIndexOf(".")).replace(/\\/g, "/");
}

0 comments on commit 055e753

Please sign in to comment.