Skip to content

Better separate type declarations #5695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
36 changes: 8 additions & 28 deletions Makefile.dryice.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var build = require('architect-build/build');
var {
updateDeclarationModuleNames,
generateDeclaration,
SEPARATE_MODULES
bundleDtsFiles,
} = require('./tool/ace_declaration_generator');

var ACE_HOME = __dirname;
Expand Down Expand Up @@ -179,29 +179,16 @@ function ace() {
}
}

function correctDeclarationsForBuild(path, additionalDeclarations) {
function correctDeclarationsForBuild(path) {
var definitions = fs.readFileSync(path, 'utf8');
var newDefinitions = updateDeclarationModuleNames(definitions);
if (additionalDeclarations) {
newDefinitions = newDefinitions + '\n' + additionalDeclarations;
}
if (/ace\.d\.ts$/.test(path)) {
var aceRequire = "$1\n export function require(name: string): any;";
newDefinitions = newDefinitions.replace(/(declare\smodule\s"ace\-builds"\s{)/, aceRequire);
}
fs.writeFileSync(path, newDefinitions);
fs.writeFileSync(path, newDefinitions, "utf-8");
}

function buildTypes() {
// ace-builds package has different structure and can't use mode types defined for the ace-code.
var paths = fs.readdirSync(BUILD_DIR + '/src-noconflict');

var typeDir = BUILD_DIR + "/types";

if (!fs.existsSync(typeDir)) {
fs.mkdirSync(typeDir);
}

fs.readdirSync(BUILD_DIR + '/src-noconflict/snippets').forEach(function(path) {
paths.push("snippets/" + path);
});
Expand All @@ -218,21 +205,13 @@ function buildTypes() {
return "declare module 'ace-builds/src-noconflict/" + moduleName + "';";
}
}).filter(Boolean)).join("\n") + "\n";

fs.copyFileSync(ACE_HOME + '/ace-internal.d.ts', BUILD_DIR + '/ace.d.ts');
generateDeclaration(BUILD_DIR + '/ace.d.ts');

generateDeclaration();
fs.copyFileSync(ACE_HOME + '/ace-modes.d.ts', BUILD_DIR + '/ace-modes.d.ts');
correctDeclarationsForBuild(BUILD_DIR + '/ace.d.ts', pathModules);
correctDeclarationsForBuild(BUILD_DIR + '/ace-modes.d.ts');
let finalDeclaration = bundleDtsFiles() + "\n" + pathModules;
finalDeclaration = finalDeclaration.replace(/(declare\smodule\s"ace\-builds"\s{)/, "$1\n export function require(name: string): any;");

let allModules = SEPARATE_MODULES;
allModules.push("modules"); // core modules
allModules.forEach(function (key) {
let fileName = '/ace-' + key + '.d.ts';
fs.copyFileSync(ACE_HOME + '/types' + fileName, BUILD_DIR + '/types' + fileName);
correctDeclarationsForBuild(BUILD_DIR + '/types' + fileName);
});

var esmUrls = [];

var loader = paths.map(function(path) {
Expand All @@ -247,6 +226,7 @@ function buildTypes() {
}).join('\n');
var esmLoader = esmUrls.join('\n');

fs.writeFileSync(BUILD_DIR + '/ace.d.ts', finalDeclaration, "utf8");
fs.writeFileSync(BUILD_DIR + '/webpack-resolver.js', loader, "utf8");
fs.writeFileSync(BUILD_DIR + '/esm-resolver.js', esmLoader, "utf8");
}
Expand Down
Loading
Loading