Skip to content

Commit

Permalink
Generate public types from ace-internal.d.ts (#5427)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkslanc authored Nov 23, 2024
1 parent b3625f3 commit 690052d
Show file tree
Hide file tree
Showing 30 changed files with 8,781 additions and 1,711 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,17 @@ jobs:
fi
fi
# check types
- run: npm run update-types
- run: node_modules/.bin/tsc --noImplicitAny --strict --noUnusedLocals --noImplicitReturns --noUnusedParameters --noImplicitThis ace.d.ts
- run: npm run typecheck
- run: git diff --exit-code ./ace-modes.d.ts ./ace.d.ts
- run: |
set -x;
npx tsc -v;
npm run update-types;
git diff --color --exit-code ./ace*d.ts;
npm run typecheck;
node_modules/.bin/tsc --noImplicitAny --strict --noUnusedLocals --noImplicitReturns --noUnusedParameters --noImplicitThis ace.d.ts;
- run: |
set -x;
./tool/test-npm-package.sh
# upload to codecov
- uses: codecov/codecov-action@v3
with:
token: d8edca4b-8e97-41e5-b54e-34c7cf3b2d47
Expand Down
45 changes: 36 additions & 9 deletions Makefile.dryice.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ var fs = require("fs");
var path = require("path");
var copy = require('architect-build/copy');
var build = require('architect-build/build');
var {
updateDeclarationModuleNames,
generateDeclaration,
SEPARATE_MODULES
} = require('./tool/ace_declaration_generator');

var ACE_HOME = __dirname;
var BUILD_DIR = ACE_HOME + "/build";
Expand Down Expand Up @@ -174,20 +179,30 @@ function ace() {
}
}

function correctDeclarationsForBuild(path, additionalDeclarations) {
var definitions = fs.readFileSync(path, 'utf8');
var newDefinitions = updateDeclarationModuleNames(definitions);
if (additionalDeclarations) {
newDefinitions = newDefinitions + '\n' + additionalDeclarations;
}
fs.writeFileSync(path, newDefinitions);
}

function buildTypes() {
var aceCodeModeDefinitions = '/// <reference path="./ace-modes.d.ts" />';
var aceCodeExtensionDefinitions = '/// <reference path="./ace-extensions.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, '').replace(aceCodeExtensionDefinitions, '');
var paths = fs.readdirSync(BUILD_DIR + '/src-noconflict');
var moduleRef = '/// <reference path="./ace-modules.d.ts" />';

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);
});

var moduleNameRegex = /^(mode|theme|ext|keybinding)-|^snippets\//;
var moduleNameRegex = /^(keybinding)-/;

var pathModules = [
"declare module 'ace-builds/webpack-resolver';",
Expand All @@ -199,9 +214,21 @@ function buildTypes() {
return "declare module 'ace-builds/src-noconflict/" + moduleName + "';";
}
}).filter(Boolean)).join("\n") + "\n";

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

fs.copyFileSync(ACE_HOME + '/ace-internal.d.ts', BUILD_DIR + '/ace.d.ts');
generateDeclaration(BUILD_DIR + '/ace.d.ts');
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 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 Down
20 changes: 0 additions & 20 deletions ace-extensions.d.ts

This file was deleted.

8 changes: 0 additions & 8 deletions ace-internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,6 @@ declare module "./src/edit_session" {
$useWorker?: boolean,
$wrapAsCode?: boolean,
$indentedSoftWrap?: boolean,
widgetManager?: any,
$bracketHighlight?: any,
$selectionMarker?: number,
lineWidgetsWidth?: number,
Expand All @@ -1357,12 +1356,6 @@ declare module "./src/edit_session" {
$occurMatchingLines?: any,
$useEmacsStyleLineStart?: boolean,
$selectLongWords?: boolean,
curOp?: {
command: {},
args: string,
scrollTop: number,
[key: string]: any;
},

getSelectionMarkers(): any[],
}
Expand All @@ -1375,7 +1368,6 @@ declare module "./src/edit_session/fold" {
}
}

// @ts-expect-error
declare module "./src/placeholder" {
export interface PlaceHolder extends Ace.EventEmitter<Ace.PlaceHolderEvents> {
}
Expand Down
Loading

0 comments on commit 690052d

Please sign in to comment.