@ws-ui/vite-plugins 1.5.12 → 1.5.14

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.
@@ -8,6 +8,7 @@ export default function monacoEditorPlugin(options = {}) {
8
8
  const languageWorkers = options.languageWorkers ||
9
9
  Object.keys(languageWorksByLabel);
10
10
  const publicPath = options.publicPath || 'assets';
11
+ const nodeModulesDir = options.nodeModulesDir || 'node_modules';
11
12
  const globalAPI = options.globalAPI || false;
12
13
  const customWorkers = options.customWorkers || [];
13
14
  const forceBuildCDN = options.forceBuildCDN || false;
@@ -84,7 +85,7 @@ export default function monacoEditorPlugin(options = {}) {
84
85
  const filename = getFilename(work);
85
86
  if (!fs.existsSync(cacheDir + filename)) {
86
87
  esbuild.buildSync({
87
- entryPoints: [resolveMonacoPath(work.entry)],
88
+ entryPoints: [resolveMonacoPath(work.entry, nodeModulesDir)],
88
89
  bundle: true,
89
90
  outfile: cacheDir + filename,
90
91
  });
@@ -18,6 +18,7 @@ export interface IMonacoEditorOpts {
18
18
  */
19
19
  publicPath?: string;
20
20
  customDistPath?: (root: string, buildOutDir: string, base: string) => string;
21
+ nodeModulesDir?: string;
21
22
  forceBuildCDN?: boolean;
22
23
  /**
23
24
  * Specify whether the editor API should be exposed through a global `monaco` object or not. This
@@ -2,6 +2,6 @@ import { IMonacoEditorOpts, IWorkerDefinition } from './types.js';
2
2
  /**
3
3
  * Return a resolved path for a given Monaco file.
4
4
  */
5
- export declare function resolveMonacoPath(filePath: string): string;
5
+ export declare function resolveMonacoPath(filePath: string, nodeModulesDir?: string): string;
6
6
  export declare function getWorks(options: IMonacoEditorOpts): IWorkerDefinition[];
7
7
  export declare function isCDN(publicPath: string): boolean;
@@ -3,16 +3,16 @@ import { languageWorksByLabel } from './languageWork.js';
3
3
  /**
4
4
  * Return a resolved path for a given Monaco file.
5
5
  */
6
- export function resolveMonacoPath(filePath) {
6
+ export function resolveMonacoPath(filePath, nodeModulesDir = 'node_modules') {
7
7
  try {
8
- return path.resolve(process.cwd(), '..', '..', 'node_modules', filePath);
8
+ return path.resolve(process.cwd(), nodeModulesDir, filePath);
9
9
  }
10
10
  catch (err) {
11
11
  return path.resolve(filePath);
12
12
  }
13
13
  }
14
14
  export function getWorks(options) {
15
- let works = (options.languageWorkers || [])
15
+ const works = (options.languageWorkers || [])
16
16
  .map((work) => languageWorksByLabel[work])
17
17
  .filter(Boolean);
18
18
  works.push(...(options.customWorkers || []));
@@ -40,6 +40,7 @@ export function getWorkPath(works, options, config) {
40
40
  }
41
41
  export function workerMiddleware(middlewares, config, options) {
42
42
  const works = getWorks(options);
43
+ const nodeModulesDir = options.nodeModulesDir || 'node_modules';
43
44
  // clear cacheDir
44
45
  if (fs.existsSync(cacheDir)) {
45
46
  fs.rmdirSync(cacheDir, { recursive: true, force: true });
@@ -49,7 +50,7 @@ export function workerMiddleware(middlewares, config, options) {
49
50
  middlewares.use(config.base + options.publicPath + '/' + filename, function (_req, res, _next) {
50
51
  if (!fs.existsSync(cacheDir + filename)) {
51
52
  esbuild.buildSync({
52
- entryPoints: [resolveMonacoPath(work.entry)],
53
+ entryPoints: [resolveMonacoPath(work.entry, nodeModulesDir)],
53
54
  bundle: true,
54
55
  outfile: cacheDir + filename,
55
56
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ws-ui/vite-plugins",
3
- "version": "1.5.12",
3
+ "version": "1.5.14",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -9,6 +9,7 @@
9
9
  "dist"
10
10
  ],
11
11
  "scripts": {
12
+ "prepack": "npm run build",
12
13
  "build": "tsc",
13
14
  "publish": "npm publish --ignore-scripts --access public"
14
15
  },