Skip to content

Commit

Permalink
New version 4.1.3 Read more https://github.com/xdan/jodit/blob/main/C…
Browse files Browse the repository at this point in the history
  • Loading branch information
xdan committed Apr 8, 2024
1 parent 3d0767e commit 59e6d4c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 19 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jodit",
"version": "4.1.2",
"version": "4.1.3",
"description": "Jodit is an awesome and useful wysiwyg editor with filebrowser",
"main": "build/jodit.min.js",
"types": "./types/index.d.ts",
Expand Down
57 changes: 41 additions & 16 deletions tools/utils/resolve-alias-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ const argv = yargs(hideBin(process.argv))
})
.parseSync();

const globalMaps = {
const globalMaps: Record<
string,
boolean | string | number | Record<string, boolean | string | number>
> = {
'process.env.FAT_MODE': false,
'process.env.APP_VERSION': argv.ver,
'process.env.TARGET_ES': 'es2020',
'process.env.IS_ES_MODERN': true,
'process.env.IS_ES_NEXT': true,
'process.env.IS_PROD': true,
'process.env.IS_TEST': false,
'process.env.TOKENS': {},
'process.env.HOMEPAGE': 'https://xdsoft.net/jodit/'
} as const;

Expand Down Expand Up @@ -142,6 +146,8 @@ function resoleAliasImports(dirPath: string): void {
return modulePath;
};

const f = ts.factory;

const transformer = (
ctx: ts.TransformationContext
): ts.Transformer<any> => {
Expand All @@ -159,15 +165,34 @@ function resoleAliasImports(dirPath: string): void {
throw Error(`Unknown variable: ${name}`);
}

const bool = globalMaps[name]
? ts.factory.createTrue()
: ts.factory.createFalse();
const obj = globalMaps[name];
if (typeof obj === 'boolean') {
return obj ? f.createTrue() : f.createFalse();
}

if (typeof obj === 'string') {
return f.createStringLiteral(obj);
}

return typeof globalMaps[name] === 'boolean'
? bool
: ts.factory.createStringLiteral(
globalMaps[name].toString()
if (typeof obj === 'number') {
return f.createNumericLiteral(obj);
}

return f.createObjectLiteralExpression(
Object.keys(obj).map(key => {
const value = obj[key];
return f.createPropertyAssignment(
f.createIdentifier(key),
typeof value === 'boolean'
? value
? f.createTrue()
: f.createFalse()
: typeof value === 'string'
? f.createStringLiteral(value)
: f.createNumericLiteral(value)
);
})
);
}

if (
Expand All @@ -176,22 +201,22 @@ function resoleAliasImports(dirPath: string): void {
node.literal?.getText()
) {
const newPath = resolvePath(node.literal.getText());
return ts.factory.updateLiteralTypeNode(
return f.updateLiteralTypeNode(
node,
ts.factory.createStringLiteral(newPath)
f.createStringLiteral(newPath)
);
}

if (
ts.isCallExpression(node) &&
node.expression.getText() === 'require'
) {
return ts.factory.updateCallExpression(
return f.updateCallExpression(
node,
node.expression,
node.typeArguments,
[
ts.factory.createStringLiteral(
f.createStringLiteral(
resolvePath(node.arguments[0].getText())
)
]
Expand All @@ -213,11 +238,11 @@ function resoleAliasImports(dirPath: string): void {
const newPath = resolvePath(
node.moduleSpecifier.getText()
);
return ts.factory.updateImportDeclaration(
return f.updateImportDeclaration(
node,
node.modifiers,
node.importClause,
ts.factory.createStringLiteral(newPath),
f.createStringLiteral(newPath),
node.assertClause
);
}
Expand All @@ -226,12 +251,12 @@ function resoleAliasImports(dirPath: string): void {
const newPath = resolvePath(
node.moduleSpecifier.getText()
);
return ts.factory.updateExportDeclaration(
return f.updateExportDeclaration(
node,
node.modifiers,
node.isTypeOnly,
node.exportClause,
ts.factory.createStringLiteral(newPath),
f.createStringLiteral(newPath),
node.assertClause
);
}
Expand Down

0 comments on commit 59e6d4c

Please sign in to comment.