@ws-ui/vite-plugins 1.9.1 → 1.10.0
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.
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import importMetaUrlPlugin from './esbuild-plugin-import-meta-url';
|
|
2
|
-
import
|
|
3
|
-
import standaloneEditorPlugin from './standalone-editor-plugin';
|
|
4
|
-
|
|
1
|
+
import importMetaUrlPlugin from './esbuild-plugin-import-meta-url/index.js';
|
|
2
|
+
import excludeFilesPlugin from './exclude-files-plugin/index.js';
|
|
3
|
+
import standaloneEditorPlugin from './standalone-editor-plugin/index.js';
|
|
4
|
+
import loadVscodeCssPlugin from './vite-plugin-load-vscode-css/index.js';
|
|
5
|
+
import monacoEditorPlugin from './vite-plugin-monaco-editor/index.js';
|
|
6
|
+
import thirdPartyLicensePlugin from './vite-plugin-third-party-license/index.js';
|
|
7
|
+
export { importMetaUrlPlugin, monacoEditorPlugin, standaloneEditorPlugin, thirdPartyLicensePlugin, excludeFilesPlugin, loadVscodeCssPlugin, };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import importMetaUrlPlugin from './esbuild-plugin-import-meta-url';
|
|
2
|
-
import
|
|
3
|
-
import standaloneEditorPlugin from './standalone-editor-plugin';
|
|
4
|
-
|
|
1
|
+
import importMetaUrlPlugin from './esbuild-plugin-import-meta-url/index.js';
|
|
2
|
+
import excludeFilesPlugin from './exclude-files-plugin/index.js';
|
|
3
|
+
import standaloneEditorPlugin from './standalone-editor-plugin/index.js';
|
|
4
|
+
import loadVscodeCssPlugin from './vite-plugin-load-vscode-css/index.js';
|
|
5
|
+
import monacoEditorPlugin from './vite-plugin-monaco-editor/index.js';
|
|
6
|
+
import thirdPartyLicensePlugin from './vite-plugin-third-party-license/index.js';
|
|
7
|
+
export { importMetaUrlPlugin, monacoEditorPlugin, standaloneEditorPlugin, thirdPartyLicensePlugin, excludeFilesPlugin, loadVscodeCssPlugin, };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type Plugin } from 'vite';
|
|
2
|
+
interface ThirdPartyLicensePluginOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Path to the main package.json (e.g., studio package.json)
|
|
5
|
+
*/
|
|
6
|
+
packageJsonPath: string;
|
|
7
|
+
/**
|
|
8
|
+
* List of workspace package names to include (e.g., ['store', 'shared'])
|
|
9
|
+
*/
|
|
10
|
+
workspacePackages?: string[];
|
|
11
|
+
/**
|
|
12
|
+
* Workspace root directory (where node_modules is located)
|
|
13
|
+
*/
|
|
14
|
+
workspaceRoot?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Output directory for the LICENSE file (defaults to build output dir)
|
|
17
|
+
*/
|
|
18
|
+
outputDir?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Package name for metadata (defaults to reading from package.json)
|
|
21
|
+
*/
|
|
22
|
+
packageName?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Plugin to generate LICENSE file with all third-party dependencies
|
|
26
|
+
* from the main package and optionally workspace packages
|
|
27
|
+
*/
|
|
28
|
+
export default function thirdPartyLicensePlugin(options: ThirdPartyLicensePluginOptions): Plugin;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Get license text from node_modules package directory
|
|
5
|
+
*/
|
|
6
|
+
function getLicenseText(packagePath) {
|
|
7
|
+
const licenseFiles = ['LICENSE', 'LICENSE.txt', 'LICENSE.md', 'LICENCE'];
|
|
8
|
+
for (const file of licenseFiles) {
|
|
9
|
+
const licensePath = join(packagePath, file);
|
|
10
|
+
if (existsSync(licensePath)) {
|
|
11
|
+
try {
|
|
12
|
+
return readFileSync(licensePath, 'utf-8');
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
// Continue to next file
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get package info from node_modules
|
|
23
|
+
*/
|
|
24
|
+
function getPackageInfo(packageName, nodeModulesPath) {
|
|
25
|
+
// Handle scoped packages
|
|
26
|
+
const parts = packageName.split('/');
|
|
27
|
+
let packagePath;
|
|
28
|
+
if (parts.length === 2) {
|
|
29
|
+
// Scoped package like @reduxjs/toolkit
|
|
30
|
+
const [scope, name] = parts;
|
|
31
|
+
if (scope && name) {
|
|
32
|
+
packagePath = join(nodeModulesPath, scope, name);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
packagePath = join(nodeModulesPath, packageName);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
packagePath = join(nodeModulesPath, packageName);
|
|
40
|
+
}
|
|
41
|
+
if (!existsSync(packagePath)) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const packageJsonPath = join(packagePath, 'package.json');
|
|
45
|
+
if (!existsSync(packageJsonPath)) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
|
|
50
|
+
const license = typeof packageJson.license === 'string'
|
|
51
|
+
? packageJson.license
|
|
52
|
+
: packageJson.license?.type || 'UNKNOWN';
|
|
53
|
+
return {
|
|
54
|
+
name: packageJson.name || packageName,
|
|
55
|
+
version: packageJson.version || 'UNKNOWN',
|
|
56
|
+
license,
|
|
57
|
+
licenseText: getLicenseText(packagePath),
|
|
58
|
+
repository: typeof packageJson.repository === 'string'
|
|
59
|
+
? packageJson.repository
|
|
60
|
+
: packageJson.repository?.url || undefined,
|
|
61
|
+
author: typeof packageJson.author === 'string'
|
|
62
|
+
? packageJson.author
|
|
63
|
+
: packageJson.author?.name || undefined,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Collect dependencies from a package.json file
|
|
72
|
+
*/
|
|
73
|
+
function collectDependencies(packageJsonPath, nodeModulesPath, sourceName) {
|
|
74
|
+
const dependencies = new Map();
|
|
75
|
+
if (!existsSync(packageJsonPath)) {
|
|
76
|
+
return dependencies;
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
|
|
80
|
+
const allDeps = {
|
|
81
|
+
...packageJson.dependencies,
|
|
82
|
+
...packageJson.peerDependencies,
|
|
83
|
+
};
|
|
84
|
+
for (const [packageName] of Object.entries(allDeps)) {
|
|
85
|
+
// Skip workspace packages
|
|
86
|
+
if (packageName.startsWith('@ws-ui/') ||
|
|
87
|
+
packageName.startsWith('@qodly/')) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
// Skip if we already have this package
|
|
91
|
+
if (dependencies.has(packageName)) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const info = getPackageInfo(packageName, nodeModulesPath);
|
|
95
|
+
if (info) {
|
|
96
|
+
info.source = sourceName;
|
|
97
|
+
dependencies.set(packageName, info);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
console.warn(`Failed to read ${packageJsonPath}:`, error);
|
|
103
|
+
}
|
|
104
|
+
return dependencies;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Plugin to generate LICENSE file with all third-party dependencies
|
|
108
|
+
* from the main package and optionally workspace packages
|
|
109
|
+
*/
|
|
110
|
+
export default function thirdPartyLicensePlugin(options) {
|
|
111
|
+
return {
|
|
112
|
+
name: 'third-party-license-plugin',
|
|
113
|
+
writeBundle() {
|
|
114
|
+
const { packageJsonPath, workspacePackages = [], workspaceRoot, outputDir, packageName, } = options;
|
|
115
|
+
// Determine paths
|
|
116
|
+
const packageDir = resolve(packageJsonPath, '..');
|
|
117
|
+
const resolvedWorkspaceRoot = workspaceRoot || resolve(packageDir, '../..');
|
|
118
|
+
const nodeModulesPath = resolve(resolvedWorkspaceRoot, 'node_modules');
|
|
119
|
+
const distDir = outputDir ||
|
|
120
|
+
resolve(packageDir, process.env.VITE_BUILD_TARGET || 'dist');
|
|
121
|
+
const licenseDestPath = resolve(distDir, 'LICENSE');
|
|
122
|
+
// Collect dependencies from main package
|
|
123
|
+
const mainPackageJson = resolve(packageDir, 'package.json');
|
|
124
|
+
const allDependencies = collectDependencies(mainPackageJson, nodeModulesPath, packageName || 'main');
|
|
125
|
+
// Collect dependencies from workspace packages
|
|
126
|
+
for (const pkg of workspacePackages) {
|
|
127
|
+
const packageJsonPath = resolve(resolvedWorkspaceRoot, 'packages', pkg, 'package.json');
|
|
128
|
+
const pkgDeps = collectDependencies(packageJsonPath, nodeModulesPath, `@ws-ui/${pkg}`);
|
|
129
|
+
// Merge dependencies (keep first occurrence)
|
|
130
|
+
for (const [name, info] of pkgDeps.entries()) {
|
|
131
|
+
if (!allDependencies.has(name)) {
|
|
132
|
+
allDependencies.set(name, info);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// Convert to array and sort
|
|
137
|
+
const licenseInfos = Array.from(allDependencies.values());
|
|
138
|
+
licenseInfos.sort((a, b) => a.name.localeCompare(b.name));
|
|
139
|
+
// Read main package.json for metadata
|
|
140
|
+
let packageJsonData = {};
|
|
141
|
+
if (existsSync(mainPackageJson)) {
|
|
142
|
+
try {
|
|
143
|
+
packageJsonData = JSON.parse(readFileSync(mainPackageJson, 'utf-8'));
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
// Ignore
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const finalPackageName = packageName || packageJsonData.name || 'unknown';
|
|
150
|
+
const finalVersion = packageJsonData.version || 'UNKNOWN';
|
|
151
|
+
// Generate LICENSE file
|
|
152
|
+
let licenseContent = `THIRD-PARTY LICENSES
|
|
153
|
+
====================
|
|
154
|
+
|
|
155
|
+
This file contains the licenses of all open source dependencies used in this package${workspacePackages.length > 0
|
|
156
|
+
? ',\nincluding dependencies from workspace packages.'
|
|
157
|
+
: '.'}
|
|
158
|
+
|
|
159
|
+
Generated on: ${new Date().toISOString()}
|
|
160
|
+
Package: ${finalPackageName}
|
|
161
|
+
Version: ${finalVersion}
|
|
162
|
+
|
|
163
|
+
`;
|
|
164
|
+
// Group by license type
|
|
165
|
+
const byLicense = {};
|
|
166
|
+
for (const info of licenseInfos) {
|
|
167
|
+
const licenseKey = info.license || 'UNKNOWN';
|
|
168
|
+
if (!byLicense[licenseKey]) {
|
|
169
|
+
byLicense[licenseKey] = [];
|
|
170
|
+
}
|
|
171
|
+
byLicense[licenseKey].push(info);
|
|
172
|
+
}
|
|
173
|
+
// Write summary
|
|
174
|
+
licenseContent += '## Summary\n\n';
|
|
175
|
+
licenseContent += '| License | Count | Packages |\n';
|
|
176
|
+
licenseContent += '|---------|-------|----------|\n';
|
|
177
|
+
for (const [license, packages] of Object.entries(byLicense)) {
|
|
178
|
+
const packageNames = packages.map((p) => p.name).join(', ');
|
|
179
|
+
licenseContent += `| ${license} | ${packages.length} | ${packageNames} |\n`;
|
|
180
|
+
}
|
|
181
|
+
licenseContent += '\n\n## Detailed License Information\n\n';
|
|
182
|
+
// Write detailed information for each package
|
|
183
|
+
for (const info of licenseInfos) {
|
|
184
|
+
licenseContent += `### ${info.name} (v${info.version})\n\n`;
|
|
185
|
+
licenseContent += `**License:** ${info.license}\n\n`;
|
|
186
|
+
if (info.source) {
|
|
187
|
+
licenseContent += `**Source:** ${info.source}\n\n`;
|
|
188
|
+
}
|
|
189
|
+
if (info.author) {
|
|
190
|
+
licenseContent += `**Author:** ${info.author}\n\n`;
|
|
191
|
+
}
|
|
192
|
+
if (info.repository) {
|
|
193
|
+
licenseContent += `**Repository:** ${info.repository}\n\n`;
|
|
194
|
+
}
|
|
195
|
+
if (info.licenseText) {
|
|
196
|
+
licenseContent += `**License Text:**\n\n\`\`\`\n${info.licenseText}\n\`\`\`\n\n`;
|
|
197
|
+
}
|
|
198
|
+
licenseContent += '---\n\n';
|
|
199
|
+
}
|
|
200
|
+
writeFileSync(licenseDestPath, licenseContent, 'utf-8');
|
|
201
|
+
console.log(`✅ Generated LICENSE file with ${licenseInfos.length} dependencies`);
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
}
|