Skip to content

Commit d7809fa

Browse files
committed
chore: change extension/prettier worker to esmodules for xml prettify
1 parent b4e9a82 commit d7809fa

File tree

14 files changed

+203
-165
lines changed

14 files changed

+203
-165
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ module.exports = {
9797
"worker": true
9898
},
9999
"parserOptions": {
100-
"ecmaVersion": 2019,
100+
"ecmaVersion": 2020,
101101
"sourceType": "module",
102102
"ecmaFeatures": {
103103
"arrowFunctions": true,

docs/generatedApiDocs/GitHub-API-Index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,5 @@ The list of all APIs for phoenix.
1414
1. [utils/Metrics](Metrics-API)
1515
1. [utils/StringUtils](StringUtils-API)
1616
1. [widgets/NotificationUI](NotificationUI-API)
17-
1. [worker/ExtensionsWorker](ExtensionsWorker-API)
1817
1. [worker/IndexingWorker](IndexingWorker-API)
1918
1. [worker/WorkerComm](WorkerComm-API)

docs/generatedApiDocs/worker/ExtensionsWorker-API.md

Lines changed: 0 additions & 78 deletions
This file was deleted.

docs/generatedApiDocs/worker/WorkerComm-API.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ Type: [function][1]
177177
### Parameters
178178

179179
* `scriptURL` **[string][2]** the Full url to load.
180+
* `isModule` **[boolean][5]** if the url is a module url
180181

181182
### Examples
182183

@@ -188,6 +189,8 @@ WorkerComm.createWorkerComm(_myWorker, exports);
188189
let ExtensionUtils = brackets.getModule("utils/ExtensionUtils");
189190
let addWorkerScriptPath = ExtensionUtils.getModulePath(module, "add_worker_Script.js")
190191
await exports.loadScriptInWorker(addWorkerScriptPath);
192+
// if the worker is an es-module, then set optional isModule to true
193+
// Eg.loadScriptInWorker(addWorkerScriptPath, true);
191194
```
192195

193196
## EVENT_WORKER_COMM_INIT_COMPLETE
@@ -201,3 +204,5 @@ Raised on main thread when WorkerComm is loaded in the web-worker and is ready.
201204
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
202205

203206
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
207+
208+
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean

gulpfile.js/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ function _listFilesInDir(dir) {
353353
});
354354
}
355355

356-
const ALLOWED_EXTENSIONS_TO_CACHE = ["js", "html", "htm", "xml", "xhtml", "css", "less", "scss", "ttf", "woff", "woff2", "eot",
356+
const ALLOWED_EXTENSIONS_TO_CACHE = ["js", "html", "htm", "xml", "xhtml", "mjs",
357+
"css", "less", "scss", "ttf", "woff", "woff2", "eot",
357358
"txt", "otf",
358359
"json", "config",
359360
"zip",

gulpfile.js/thirdparty-lib-copy.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ let copyThirdPartyLibs = series(
162162
copyFiles.bind(copyFiles, ['node_modules/@prettier/plugin-php/*.js'],
163163
'src/thirdparty/prettier/php'),
164164
copyLicence.bind(copyLicence, 'node_modules/@prettier/plugin-php/LICENSE', 'prettier-php'),
165+
copyFiles.bind(copyFiles, ['node_modules/@prettier/plugin-xml/src/*.js'],
166+
'src/thirdparty/prettier/xml'),
167+
copyLicence.bind(copyLicence, 'node_modules/@prettier/plugin-xml/LICENSE', 'prettier-xml'),
165168
// font-awesome
166169
copyFiles.bind(copyFiles, ['node_modules/@fortawesome/fontawesome-free/css/all.min.css'],
167170
'src/thirdparty/fontawesome/css'),

package-lock.json

Lines changed: 62 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"@phcode/fs": "^3.0.0",
9393
"@pixelbrackets/gfm-stylesheet": "^1.1.0",
9494
"@prettier/plugin-php": "^0.22.2",
95+
"@prettier/plugin-xml": "^3.3.1",
9596
"@uiw/file-icons": "^1.3.2",
9697
"bootstrap": "^5.1.3",
9798
"browser-mime": "^1.0.1",

src/extensions/default/Phoenix-prettier/main.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ define(function (require, exports, module) {
216216
return new Promise((resolve, reject)=>{
217217
let filepath = editor.document.file.fullPath;
218218
let languageId = LanguageManager.getLanguageForPath(filepath).getId();
219-
_loadPlugins(languageId);
220219
console.log("Beautifying with language id: ", languageId);
221220

222221
let selection = editor.getSelections();
@@ -228,12 +227,13 @@ define(function (require, exports, module) {
228227

229228
let options = prefs.get("options");
230229
let indentWithTabs = Editor.getUseTabChar(filepath);
230+
options._usePlugin = parsersForLanguage[languageId];
231231
Object.assign(options, {
232232
parser: parsersForLanguage[languageId],
233233
tabWidth: indentWithTabs ? Editor.getTabSize() : Editor.getSpaceUnits(),
234234
useTabs: indentWithTabs,
235235
filepath: filepath,
236-
endOfLine: Phoenix.platform === 'win' ? "crlf": "lf"
236+
endOfLine: "lf" // codemirror always does lf and only crlf before disk write in windows.
237237
});
238238
let prettierParams ={
239239
text: editor.document.getText(),
@@ -264,28 +264,18 @@ define(function (require, exports, module) {
264264
});
265265
}
266266

267-
let loadedPlugins = {};
268-
function _loadPlugins(languageId) {
269-
if(!loadedPlugins[languageId] && parsersForLanguage[languageId]){
270-
ExtensionsWorker.execPeer("loadPrettierPlugin", parsersForLanguage[languageId]).catch(err=>{
271-
console.error("Error Loading Prettier Plugin", err);
272-
});
273-
}
274-
loadedPlugins[languageId] = true;
275-
}
276-
277267
AppInit.appReady(function () {
278-
ExtensionsWorker.loadScriptInWorker(`${module.uri}/../worker/prettier-helper.js`);
268+
ExtensionsWorker.loadScriptInWorker(`${module.uri}/../worker/prettier-helper.js`, true);
279269
BeautificationManager.registerBeautificationProvider(exports, Object.keys(parsersForLanguage));
280270
});
281271

282272
function beautifyTextProvider(textToBeautify, filePathOrFileName) {
283273
return new Promise((resolve, reject)=>{
284274
let languageId = LanguageManager.getLanguageForPath(filePathOrFileName).getId();
285-
_loadPlugins(languageId);
286275
console.log("Beautifying text with language id: ", languageId);
287276
let options = prefs.get("options");
288277
let indentWithTabs = Editor.getUseTabChar(filePathOrFileName);
278+
options._usePlugin = parsersForLanguage[languageId];
289279
Object.assign(options, {
290280
parser: parsersForLanguage[languageId],
291281
tabWidth: indentWithTabs ? Editor.getTabSize() : Editor.getSpaceUnits(),

0 commit comments

Comments
 (0)