Skip to content

Commit 942fff0

Browse files
committed
fix(webworker not working)
1 parent bf9953e commit 942fff0

9 files changed

Lines changed: 402 additions & 55 deletions

dist/214.js

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

dist/36.js

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

dist/main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/src_worker_js.js

Lines changed: 223 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,242 @@
77
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
88
*/
99
/******/ (function() { // webpackBootstrap
10+
/******/ "use strict";
1011
/******/ var __webpack_modules__ = ({
1112

13+
/***/ "./src/prettierPlugins.js":
14+
/*!********************************!*\
15+
!*** ./src/prettierPlugins.js ***!
16+
\********************************/
17+
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
18+
19+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var prettier_plugins_html__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! prettier/plugins/html */ \"./node_modules/prettier/plugins/html.mjs\");\n/* harmony import */ var prettier_plugins_babel__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! prettier/plugins/babel */ \"./node_modules/prettier/plugins/babel.mjs\");\n/* harmony import */ var prettier_plugins_graphql__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! prettier/plugins/graphql */ \"./node_modules/prettier/plugins/graphql.mjs\");\n/* harmony import */ var prettier_plugins_angular__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! prettier/plugins/angular */ \"./node_modules/prettier/plugins/angular.mjs\");\n/* harmony import */ var prettier_plugins_estree__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! prettier/plugins/estree */ \"./node_modules/prettier/plugins/estree.mjs\");\n/* harmony import */ var prettier_plugins_flow__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! prettier/plugins/flow */ \"./node_modules/prettier/plugins/flow.mjs\");\n/* harmony import */ var prettier_plugins_glimmer__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! prettier/plugins/glimmer */ \"./node_modules/prettier/plugins/glimmer.mjs\");\n/* harmony import */ var prettier_plugins_markdown__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! prettier/plugins/markdown */ \"./node_modules/prettier/plugins/markdown.mjs\");\n/* harmony import */ var prettier_plugins_meriyah__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! prettier/plugins/meriyah */ \"./node_modules/prettier/plugins/meriyah.mjs\");\n/* harmony import */ var prettier_plugins_postcss__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! prettier/plugins/postcss */ \"./node_modules/prettier/plugins/postcss.mjs\");\n/* harmony import */ var prettier_plugins_typescript__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! prettier/plugins/typescript */ \"./node_modules/prettier/plugins/typescript.mjs\");\n/* harmony import */ var prettier_plugins_yaml__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! prettier/plugins/yaml */ \"./node_modules/prettier/plugins/yaml.mjs\");\n/* harmony import */ var prettier_plugins_acorn__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! prettier/plugins/acorn */ \"./node_modules/prettier/plugins/acorn.mjs\");\n\n\n\n\n\n\n\n\n\n\n\n\n\n/* harmony default export */ __webpack_exports__[\"default\"] = ([prettier_plugins_babel__WEBPACK_IMPORTED_MODULE_1__[\"default\"], prettier_plugins_graphql__WEBPACK_IMPORTED_MODULE_2__[\"default\"], prettier_plugins_angular__WEBPACK_IMPORTED_MODULE_3__[\"default\"], prettier_plugins_estree__WEBPACK_IMPORTED_MODULE_4__[\"default\"], prettier_plugins_flow__WEBPACK_IMPORTED_MODULE_5__[\"default\"], prettier_plugins_glimmer__WEBPACK_IMPORTED_MODULE_6__[\"default\"], prettier_plugins_html__WEBPACK_IMPORTED_MODULE_0__[\"default\"], prettier_plugins_markdown__WEBPACK_IMPORTED_MODULE_7__[\"default\"], prettier_plugins_meriyah__WEBPACK_IMPORTED_MODULE_8__[\"default\"], prettier_plugins_postcss__WEBPACK_IMPORTED_MODULE_9__[\"default\"], prettier_plugins_typescript__WEBPACK_IMPORTED_MODULE_10__[\"default\"], prettier_plugins_yaml__WEBPACK_IMPORTED_MODULE_11__[\"default\"], prettier_plugins_acorn__WEBPACK_IMPORTED_MODULE_12__[\"default\"]]);\n\n//# sourceURL=webpack://acode-plugin-prettier/./src/prettierPlugins.js?");
20+
21+
/***/ }),
22+
1223
/***/ "./src/worker.js":
1324
/*!***********************!*\
1425
!*** ./src/worker.js ***!
1526
\***********************/
16-
/***/ (function() {
27+
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
1728

18-
eval("self.onmessage = async e => {\n const {\n id,\n code,\n cursorOptions,\n action,\n scriptUrl\n } = e.data;\n if (action === \"load script\") {\n importScripts(scriptUrl);\n self.postMessage({\n action: \"script loaded\"\n });\n return;\n }\n const {\n prettier,\n plugins\n } = self.acodePluginPrettier;\n cursorOptions.plugins = plugins;\n const res = await prettier.formatWithCursor(code, cursorOptions);\n self.postMessage({\n id,\n action: \"code format\",\n res\n });\n};\n\n//# sourceURL=webpack://acode-plugin-prettier/./src/worker.js?");
29+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var prettier_standalone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! prettier/standalone */ \"./node_modules/prettier/standalone.mjs\");\n/* harmony import */ var _prettierPlugins__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./prettierPlugins */ \"./src/prettierPlugins.js\");\n\n\nself.onmessage = async e => {\n const {\n id,\n code,\n cursorOptions,\n action,\n scriptUrl\n } = e.data;\n if (action === \"load script\") {\n importScripts(scriptUrl);\n self.postMessage({\n action: \"script loaded\"\n });\n return;\n }\n cursorOptions.plugins = _prettierPlugins__WEBPACK_IMPORTED_MODULE_1__[\"default\"];\n const res = await prettier_standalone__WEBPACK_IMPORTED_MODULE_0__[\"default\"].formatWithCursor(code, cursorOptions);\n self.postMessage({\n id,\n action: \"code format\",\n res\n });\n};\n\n//# sourceURL=webpack://acode-plugin-prettier/./src/worker.js?");
1930

2031
/***/ })
2132

2233
/******/ });
2334
/************************************************************************/
35+
/******/ // The module cache
36+
/******/ var __webpack_module_cache__ = {};
37+
/******/
38+
/******/ // The require function
39+
/******/ function __webpack_require__(moduleId) {
40+
/******/ // Check if module is in cache
41+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
42+
/******/ if (cachedModule !== undefined) {
43+
/******/ return cachedModule.exports;
44+
/******/ }
45+
/******/ // Create a new module (and put it into the cache)
46+
/******/ var module = __webpack_module_cache__[moduleId] = {
47+
/******/ // no module.id needed
48+
/******/ // no module.loaded needed
49+
/******/ exports: {}
50+
/******/ };
51+
/******/
52+
/******/ // Execute the module function
53+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
54+
/******/
55+
/******/ // Return the exports of the module
56+
/******/ return module.exports;
57+
/******/ }
58+
/******/
59+
/******/ // expose the modules object (__webpack_modules__)
60+
/******/ __webpack_require__.m = __webpack_modules__;
61+
/******/
62+
/******/ // the startup function
63+
/******/ __webpack_require__.x = function() {
64+
/******/ // Load entry module and return exports
65+
/******/ // This entry module depends on other loaded chunks and execution need to be delayed
66+
/******/ var __webpack_exports__ = __webpack_require__.O(undefined, ["vendors-node_modules_prettier_plugins_acorn_mjs-node_modules_prettier_plugins_angular_mjs-nod-2246c6"], function() { return __webpack_require__("./src/worker.js"); })
67+
/******/ __webpack_exports__ = __webpack_require__.O(__webpack_exports__);
68+
/******/ return __webpack_exports__;
69+
/******/ };
70+
/******/
71+
/************************************************************************/
72+
/******/ /* webpack/runtime/chunk loaded */
73+
/******/ !function() {
74+
/******/ var deferred = [];
75+
/******/ __webpack_require__.O = function(result, chunkIds, fn, priority) {
76+
/******/ if(chunkIds) {
77+
/******/ priority = priority || 0;
78+
/******/ for(var i = deferred.length; i > 0 && deferred[i - 1][2] > priority; i--) deferred[i] = deferred[i - 1];
79+
/******/ deferred[i] = [chunkIds, fn, priority];
80+
/******/ return;
81+
/******/ }
82+
/******/ var notFulfilled = Infinity;
83+
/******/ for (var i = 0; i < deferred.length; i++) {
84+
/******/ var chunkIds = deferred[i][0];
85+
/******/ var fn = deferred[i][1];
86+
/******/ var priority = deferred[i][2];
87+
/******/ var fulfilled = true;
88+
/******/ for (var j = 0; j < chunkIds.length; j++) {
89+
/******/ if ((priority & 1 === 0 || notFulfilled >= priority) && Object.keys(__webpack_require__.O).every(function(key) { return __webpack_require__.O[key](chunkIds[j]); })) {
90+
/******/ chunkIds.splice(j--, 1);
91+
/******/ } else {
92+
/******/ fulfilled = false;
93+
/******/ if(priority < notFulfilled) notFulfilled = priority;
94+
/******/ }
95+
/******/ }
96+
/******/ if(fulfilled) {
97+
/******/ deferred.splice(i--, 1)
98+
/******/ var r = fn();
99+
/******/ if (r !== undefined) result = r;
100+
/******/ }
101+
/******/ }
102+
/******/ return result;
103+
/******/ };
104+
/******/ }();
105+
/******/
106+
/******/ /* webpack/runtime/define property getters */
107+
/******/ !function() {
108+
/******/ // define getter functions for harmony exports
109+
/******/ __webpack_require__.d = function(exports, definition) {
110+
/******/ for(var key in definition) {
111+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
112+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
113+
/******/ }
114+
/******/ }
115+
/******/ };
116+
/******/ }();
117+
/******/
118+
/******/ /* webpack/runtime/ensure chunk */
119+
/******/ !function() {
120+
/******/ __webpack_require__.f = {};
121+
/******/ // This file contains only the entry chunk.
122+
/******/ // The chunk loading function for additional chunks
123+
/******/ __webpack_require__.e = function(chunkId) {
124+
/******/ return Promise.all(Object.keys(__webpack_require__.f).reduce(function(promises, key) {
125+
/******/ __webpack_require__.f[key](chunkId, promises);
126+
/******/ return promises;
127+
/******/ }, []));
128+
/******/ };
129+
/******/ }();
130+
/******/
131+
/******/ /* webpack/runtime/get javascript chunk filename */
132+
/******/ !function() {
133+
/******/ // This function allow to reference async chunks and sibling chunks for the entrypoint
134+
/******/ __webpack_require__.u = function(chunkId) {
135+
/******/ // return url for filenames based on template
136+
/******/ return "" + chunkId + ".js";
137+
/******/ };
138+
/******/ }();
139+
/******/
140+
/******/ /* webpack/runtime/global */
141+
/******/ !function() {
142+
/******/ __webpack_require__.g = (function() {
143+
/******/ if (typeof globalThis === 'object') return globalThis;
144+
/******/ try {
145+
/******/ return this || new Function('return this')();
146+
/******/ } catch (e) {
147+
/******/ if (typeof window === 'object') return window;
148+
/******/ }
149+
/******/ })();
150+
/******/ }();
151+
/******/
152+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
153+
/******/ !function() {
154+
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
155+
/******/ }();
156+
/******/
157+
/******/ /* webpack/runtime/make namespace object */
158+
/******/ !function() {
159+
/******/ // define __esModule on exports
160+
/******/ __webpack_require__.r = function(exports) {
161+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
162+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
163+
/******/ }
164+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
165+
/******/ };
166+
/******/ }();
167+
/******/
168+
/******/ /* webpack/runtime/publicPath */
169+
/******/ !function() {
170+
/******/ var scriptUrl;
171+
/******/ if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + "";
172+
/******/ var document = __webpack_require__.g.document;
173+
/******/ if (!scriptUrl && document) {
174+
/******/ if (document.currentScript)
175+
/******/ scriptUrl = document.currentScript.src;
176+
/******/ if (!scriptUrl) {
177+
/******/ var scripts = document.getElementsByTagName("script");
178+
/******/ if(scripts.length) {
179+
/******/ var i = scripts.length - 1;
180+
/******/ while (i > -1 && !scriptUrl) scriptUrl = scripts[i--].src;
181+
/******/ }
182+
/******/ }
183+
/******/ }
184+
/******/ // When supporting browsers where an automatic publicPath is not supported you must specify an output.publicPath manually via configuration
185+
/******/ // or pass an empty string ("") and set the __webpack_public_path__ variable from your code to use your own logic.
186+
/******/ if (!scriptUrl) throw new Error("Automatic publicPath is not supported in this browser");
187+
/******/ scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/");
188+
/******/ __webpack_require__.p = scriptUrl;
189+
/******/ }();
190+
/******/
191+
/******/ /* webpack/runtime/importScripts chunk loading */
192+
/******/ !function() {
193+
/******/ // no baseURI
194+
/******/
195+
/******/ // object to store loaded chunks
196+
/******/ // "1" means "already loaded"
197+
/******/ var installedChunks = {
198+
/******/ "src_worker_js": 1
199+
/******/ };
200+
/******/
201+
/******/ // importScripts chunk loading
202+
/******/ var installChunk = function(data) {
203+
/******/ var chunkIds = data[0];
204+
/******/ var moreModules = data[1];
205+
/******/ var runtime = data[2];
206+
/******/ for(var moduleId in moreModules) {
207+
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
208+
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
209+
/******/ }
210+
/******/ }
211+
/******/ if(runtime) runtime(__webpack_require__);
212+
/******/ while(chunkIds.length)
213+
/******/ installedChunks[chunkIds.pop()] = 1;
214+
/******/ parentChunkLoadingFunction(data);
215+
/******/ };
216+
/******/ __webpack_require__.f.i = function(chunkId, promises) {
217+
/******/ // "1" is the signal for "already loaded"
218+
/******/ if(!installedChunks[chunkId]) {
219+
/******/ if(true) { // all chunks have JS
220+
/******/ importScripts(__webpack_require__.p + __webpack_require__.u(chunkId));
221+
/******/ }
222+
/******/ }
223+
/******/ };
224+
/******/
225+
/******/ var chunkLoadingGlobal = self["webpackChunkacode_plugin_prettier"] = self["webpackChunkacode_plugin_prettier"] || [];
226+
/******/ var parentChunkLoadingFunction = chunkLoadingGlobal.push.bind(chunkLoadingGlobal);
227+
/******/ chunkLoadingGlobal.push = installChunk;
228+
/******/
229+
/******/ // no HMR
230+
/******/
231+
/******/ // no HMR manifest
232+
/******/ }();
233+
/******/
234+
/******/ /* webpack/runtime/startup chunk dependencies */
235+
/******/ !function() {
236+
/******/ var next = __webpack_require__.x;
237+
/******/ __webpack_require__.x = function() {
238+
/******/ return __webpack_require__.e("vendors-node_modules_prettier_plugins_acorn_mjs-node_modules_prettier_plugins_angular_mjs-nod-2246c6").then(next);
239+
/******/ };
240+
/******/ }();
241+
/******/
242+
/************************************************************************/
24243
/******/
25-
/******/ // startup
26-
/******/ // Load entry module and return exports
27-
/******/ // This entry module can't be inlined because the eval devtool is used.
28-
/******/ var __webpack_exports__ = {};
29-
/******/ __webpack_modules__["./src/worker.js"]();
244+
/******/ // run startup
245+
/******/ var __webpack_exports__ = __webpack_require__.x();
30246
/******/
31247
/******/ })()
32248
;

dist/vendors-node_modules_prettier_plugins_acorn_mjs-node_modules_prettier_plugins_angular_mjs-nod-2246c6.js

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

src/main.js

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import plugin from "../plugin.json";
22
import yaml from "js-yaml";
33
import toml from "toml";
4+
import prettier from "prettier/standalone";
5+
import prettierPlugins from './prettierPlugins';
46

57
const pluginId = plugin.id;
68
const appSettings = acode.require('settings');
@@ -53,21 +55,6 @@ class AcodePrettier {
5355
}
5456
}
5557

56-
async loadScript() {
57-
if (document.getElementById("prettier-vendor-script")) {
58-
return;
59-
}
60-
61-
const $script = document.createElement("script");
62-
this.$vendorScript = $script;
63-
$script.id = "prettier-vendor-script";
64-
$script.src = acode.joinUrl(this.baseUrl, "vendor.js");
65-
return new Promise((resolve, reject) => {
66-
$script.onload = resolve;
67-
$script.onerror = reject;
68-
});
69-
}
70-
7158
static inferParser(filename) {
7259
switch (filename.slice(filename.lastIndexOf(".") + 1)) {
7360
case "html":
@@ -119,8 +106,6 @@ class AcodePrettier {
119106
async init() {
120107
if (typeof Worker !== "undefined") {
121108
this.#initializeWorker();
122-
} else {
123-
await this.loadScript();
124109
}
125110

126111
const extensions = [
@@ -173,8 +158,7 @@ class AcodePrettier {
173158
return;
174159
}
175160

176-
const { prettier, plugins } = window.acodePluginPrettier;
177-
cursorOptions.plugins = plugins;
161+
cursorOptions.plugins = prettierPlugins;
178162
const res = await prettier.formatWithCursor(code, cursorOptions);
179163
this.#setValue(session, res);
180164
}
@@ -235,11 +219,6 @@ class AcodePrettier {
235219
this.#setValue(session, res);
236220
}
237221
};
238-
239-
this.worker.postMessage({
240-
action: "load script",
241-
scriptUrl: acode.joinUrl(this.baseUrl, "vendor.js"),
242-
});
243222
}
244223

245224
#setValue(session, formattedCode) {
@@ -277,7 +256,7 @@ class AcodePrettier {
277256
".prettierrc.yml",
278257
".prettierrc.toml",
279258
".prettierrc.js",
280-
"prettier.config.js",
259+
".prettier.config.js",
281260
".prettierrc.mjs",
282261
".prettierrc.config.mjs",
283262
".prettierrc.cjs",

0 commit comments

Comments
 (0)