@ws-ui/vite-plugins 1.0.0 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,19 +9,25 @@ const importMetaUrlPlugin = {
9
9
  if (/node_modules(\/|\\)(mime-types|mime-db)/.test(args.path)) {
10
10
  return;
11
11
  }
12
- const code = readFileSync(args.path, 'utf8');
13
- const assetImportMetaUrlRE = /\bnew\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*(?:,\s*)?\)/g;
14
- let i = 0;
15
- let newCode = '';
16
- for (let match = assetImportMetaUrlRE.exec(code); match != null; match = assetImportMetaUrlRE.exec(code)) {
17
- newCode += code.slice(i, match.index);
18
- const path = match[1].slice(1, -1);
19
- const resolved = resolve(path, pathToFileURL(args.path).toString());
20
- newCode += `new URL(${JSON.stringify(fileURLToPath(resolved))}, import.meta.url)`;
21
- i = assetImportMetaUrlRE.lastIndex;
12
+ try {
13
+ const code = readFileSync(args.path, 'utf8');
14
+ const assetImportMetaUrlRE = /\bnew\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*(?:,\s*)?\)/g;
15
+ let i = 0;
16
+ let newCode = '';
17
+ for (let match = assetImportMetaUrlRE.exec(code); match != null; match = assetImportMetaUrlRE.exec(code)) {
18
+ newCode += code.slice(i, match.index);
19
+ const path = match[1].slice(1, -1);
20
+ const resolved = resolve(path, pathToFileURL(args.path).toString());
21
+ newCode += `new URL(${JSON.stringify(fileURLToPath(resolved))}, import.meta.url)`;
22
+ i = assetImportMetaUrlRE.lastIndex;
23
+ }
24
+ newCode += code.slice(i);
25
+ return { contents: newCode };
26
+ }
27
+ catch (e) {
28
+ // proceed
29
+ return;
22
30
  }
23
- newCode += code.slice(i);
24
- return { contents: newCode };
25
31
  });
26
32
  },
27
33
  };
@@ -0,0 +1,3 @@
1
+ import { Plugin } from 'vite';
2
+ declare const loadVscodeCssPlugin: Plugin;
3
+ export default loadVscodeCssPlugin;
@@ -0,0 +1,15 @@
1
+ const loadVscodeCssPlugin = {
2
+ name: 'load-vscode-css-as-string',
3
+ enforce: 'pre',
4
+ async resolveId(source, importer, options) {
5
+ const resolved = (await this.resolve(source, importer, options));
6
+ if (resolved.id.match(/node_modules\/(@codingame\/monaco-vscode|vscode|monaco-editor).*\.css$/)) {
7
+ return {
8
+ ...resolved,
9
+ id: resolved.id + '?inline',
10
+ };
11
+ }
12
+ return undefined;
13
+ },
14
+ };
15
+ export default loadVscodeCssPlugin;
@@ -1,3 +1,3 @@
1
1
  import { Plugin } from 'vite';
2
- import { IMonacoEditorOpts } from './types';
2
+ import { IMonacoEditorOpts } from './types.js';
3
3
  export default function monacoEditorPlugin(options?: IMonacoEditorOpts): Plugin;
@@ -1,9 +1,9 @@
1
1
  import esbuild from 'esbuild';
2
2
  import * as path from 'path';
3
3
  import * as fs from 'fs';
4
- import { languageWorksByLabel } from './languageWork';
5
- import { workerMiddleware, cacheDir, getFilename, getWorkPath, } from './workerMiddleware';
6
- import { getWorks, isCDN, resolveMonacoPath } from './utils';
4
+ import { languageWorksByLabel } from './languageWork.js';
5
+ import { workerMiddleware, cacheDir, getFilename, getWorkPath, } from './workerMiddleware.js';
6
+ import { getWorks, isCDN, resolveMonacoPath } from './utils.js';
7
7
  export default function monacoEditorPlugin(options = {}) {
8
8
  const languageWorkers = options.languageWorkers ||
9
9
  Object.keys(languageWorksByLabel);
@@ -35,23 +35,23 @@ export default function monacoEditorPlugin(options = {}) {
35
35
  const works = getWorks(options);
36
36
  const workerPaths = getWorkPath(works, options, resolvedConfig);
37
37
  const globals = {
38
- MonacoEnvironment: `(function (paths) {
39
- return {
40
- globalAPI: ${globalAPI},
41
- getWorkerUrl : function (moduleId, label) {
42
- var result = paths[label];
43
- if (/^((http:)|(https:)|(file:)|(\\/\\/))/.test(result)) {
44
- var currentUrl = String(window.location);
45
- var currentOrigin = currentUrl.substr(0, currentUrl.length - window.location.hash.length - window.location.search.length - window.location.pathname.length);
46
- if (result.substring(0, currentOrigin.length) !== currentOrigin) {
47
- var js = '/*' + label + '*/importScripts("' + result + '");';
48
- var blob = new Blob([js], { type: 'application/javascript' });
49
- return URL.createObjectURL(blob);
50
- }
51
- }
52
- return result;
53
- }
54
- };
38
+ MonacoEnvironment: `(function (paths) {
39
+ return {
40
+ globalAPI: ${globalAPI},
41
+ getWorkerUrl : function (moduleId, label) {
42
+ var result = paths[label];
43
+ if (/^((http:)|(https:)|(file:)|(\\/\\/))/.test(result)) {
44
+ var currentUrl = String(window.location);
45
+ var currentOrigin = currentUrl.substr(0, currentUrl.length - window.location.hash.length - window.location.search.length - window.location.pathname.length);
46
+ if (result.substring(0, currentOrigin.length) !== currentOrigin) {
47
+ var js = '/*' + label + '*/importScripts("' + result + '");';
48
+ var blob = new Blob([js], { type: 'application/javascript' });
49
+ return URL.createObjectURL(blob);
50
+ }
51
+ }
52
+ return result;
53
+ }
54
+ };
55
55
  })(${JSON.stringify(workerPaths, null, 2)})`,
56
56
  };
57
57
  const descriptor = [
@@ -1,4 +1,4 @@
1
- import { IWorkerDefinition } from './types';
1
+ import { IWorkerDefinition } from './types.js';
2
2
  export declare const languageWorkAttr: IWorkerDefinition[];
3
3
  declare const languageWorksByLabel: {
4
4
  [language: string]: IWorkerDefinition;
@@ -2,7 +2,7 @@ export const languageWorkAttr = [
2
2
  {
3
3
  label: 'editorWorkerService',
4
4
  filename: 'editor.worker.bundle.js',
5
- entry: 'monaco-editor/esm/vs/editor/editor.worker',
5
+ entry: 'monaco-editor/esm/vs/editor/editor.worker?worker',
6
6
  },
7
7
  {
8
8
  label: 'textMateWorker',
@@ -1,4 +1,4 @@
1
- import { IMonacoEditorOpts, IWorkerDefinition } from './types';
1
+ import { IMonacoEditorOpts, IWorkerDefinition } from './types.js';
2
2
  /**
3
3
  * Return a resolved path for a given Monaco file.
4
4
  */
@@ -1,11 +1,11 @@
1
1
  import * as path from 'path';
2
- import { languageWorksByLabel } from './languageWork';
2
+ import { languageWorksByLabel } from './languageWork.js';
3
3
  /**
4
4
  * Return a resolved path for a given Monaco file.
5
5
  */
6
6
  export function resolveMonacoPath(filePath) {
7
7
  try {
8
- return path.resolve(path.join(process.cwd(), 'node_modules', filePath));
8
+ return path.resolve(process.cwd(), '..', '..', 'node_modules', filePath);
9
9
  }
10
10
  catch (err) {
11
11
  return path.resolve(filePath);
@@ -1,5 +1,5 @@
1
1
  import { Connect, ResolvedConfig } from 'vite';
2
- import { IMonacoEditorOpts, IWorkerDefinition } from './types';
2
+ import { IMonacoEditorOpts, IWorkerDefinition } from './types.js';
3
3
  export declare function getFilenameByEntry(entry: string): string;
4
4
  export declare function getFilename(work: IWorkerDefinition): string;
5
5
  export declare const cacheDir = "node_modules/.monaco/";
@@ -1,4 +1,4 @@
1
- import { getWorks, isCDN, resolveMonacoPath } from './utils';
1
+ import { getWorks, isCDN, resolveMonacoPath } from './utils.js';
2
2
  import esbuild from 'esbuild';
3
3
  import * as fs from 'fs';
4
4
  import * as path from 'path';
@@ -15,8 +15,7 @@ export function getWorkPath(works, options, config) {
15
15
  for (const work of works) {
16
16
  const filename = getFilename(work);
17
17
  if (options.publicPath && isCDN(options.publicPath)) {
18
- workerPaths[work.label] =
19
- options.publicPath + '/' + filename;
18
+ workerPaths[work.label] = options.publicPath + '/' + filename;
20
19
  }
21
20
  else {
22
21
  workerPaths[work.label] =
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "@ws-ui/vite-plugins",
3
- "private": false,
4
- "version": "1.0.0",
3
+ "version": "1.0.4",
5
4
  "type": "module",
6
5
  "main": "./dist/index.js",
7
6
  "module": "./dist/index.js",
@@ -10,14 +9,15 @@
10
9
  "dist"
11
10
  ],
12
11
  "scripts": {
13
- "build": "tsc"
12
+ "build": "tsc",
13
+ "publish": "npm publish --ignore-scripts --access public"
14
14
  },
15
15
  "devDependencies": {
16
16
  "@types/node": "^20.14.9",
17
- "typescript": "^5.2.2",
18
- "vite": "^4.5.3"
17
+ "typescript": "^5.8.3",
18
+ "vite": "^6.2.1"
19
19
  },
20
20
  "dependencies": {
21
- "import-meta-resolve": "^4.0.0"
21
+ "import-meta-resolve": "^4.1.0"
22
22
  }
23
23
  }