Skip to content

Commit

Permalink
fix: add mode types, improve type definitions
Browse files Browse the repository at this point in the history
This change adds a new ace-modes.d.ts file (references in the main ace.d.ts),
which declares types for everything in the `ace/src/mode` folder.

It's been done semi-automatically, and every mode or highlight rules have the
same base type, even though technically different modes can have different
sub-types (so currently we are omitting some information).

Type definitions are excluded in the ace-builds package.

Also included small fixes for existing types, like EditSession or Config.
  • Loading branch information
ibabanov-aws committed Apr 25, 2023
1 parent 990745a commit e22bd5c
Show file tree
Hide file tree
Showing 3 changed files with 1,229 additions and 13 deletions.
10 changes: 6 additions & 4 deletions Makefile.dryice.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ function ace() {
}

function buildTypes() {
var definitions = fs.readFileSync(ACE_HOME + '/ace.d.ts', 'utf8');
var aceCodeModeDefinitions = '/// <reference path="./ace-modes.d.ts" />';
// ace-builds package has different structure and can't use mode types defined for the ace-code.
// ace-builds modes are declared along with other modules in the ace-modules.d.ts file below.
var definitions = fs.readFileSync(ACE_HOME + '/ace.d.ts', 'utf8').replace(aceCodeModeDefinitions, '');
var paths = fs.readdirSync(BUILD_DIR + '/src-noconflict');
var moduleRef = '/// <reference path="./ace-modules.d.ts" />';

Expand All @@ -193,21 +196,20 @@ function buildTypes() {

fs.writeFileSync(BUILD_DIR + '/ace.d.ts', moduleRef + '\n' + definitions);
fs.writeFileSync(BUILD_DIR + '/ace-modules.d.ts', pathModules);

var esmUrls = [];

var loader = paths.map(function(path) {
if (/\.js$/.test(path) && !/^ace\.js$/.test(path)) {
var moduleName = path.split('.')[0].replace(/-/, "/");
if (/^worker/.test(moduleName))
moduleName = "mode" + moduleName.slice(6) + "_worker";
moduleName = moduleName.replace(/keybinding/, "keyboard");

esmUrls.push("ace.config.setModuleLoader('ace/" + moduleName + "', () => import('./src-noconflict/" + path + "'));");
return "ace.config.setModuleUrl('ace/" + moduleName + "', require('file-loader?esModule=false!./src-noconflict/" + path + "'));";
}
}).join('\n');
var esmLoader = esmUrls.join('\n');

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

0 comments on commit e22bd5c

Please sign in to comment.