@hpcc-js/esbuild-plugins 1.8.7 → 1.8.9

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/src/vite-utils.ts CHANGED
@@ -1,260 +1,261 @@
1
- import { configDefaults, defineConfig, ViteUserConfig } from "vitest/config";
2
- import cssInjectedByJsPlugin from "vite-plugin-css-injected-by-js";
3
- import { viteStaticCopy } from "vite-plugin-static-copy";
4
- import { packageVersionPlugin } from "./package-version-plugin.ts";
5
- import { readFileSync } from "fs";
6
- import { resolve, dirname } from "path";
7
- import { fileURLToPath } from "url";
8
-
9
- const alias = {
10
- "d3-array": "@hpcc-js/common",
11
- "d3-brush": "@hpcc-js/common",
12
- "d3-collection": "@hpcc-js/common",
13
- "d3-color": "@hpcc-js/common",
14
- "d3-dispatch": "@hpcc-js/common",
15
- "d3-drag": "@hpcc-js/common",
16
- "d3-dsv": "@hpcc-js/common",
17
- "d3-ease": "@hpcc-js/common",
18
- "d3-format": "@hpcc-js/common",
19
- "d3-interpolate": "@hpcc-js/common",
20
- "d3-scale": "@hpcc-js/common",
21
- "d3-selection": "@hpcc-js/common",
22
- "d3-time-format": "@hpcc-js/common",
23
- "d3-transition": "@hpcc-js/common",
24
- "d3-zoom": "@hpcc-js/common"
25
- };
26
-
27
- /**
28
- * Find and read the root package.json (monorepo root)
29
- * Walks up the directory tree looking for a package.json with "workspaces"
30
- */
31
- function getRootPackageVersion(): string {
32
- try {
33
- // Try to find root package.json by walking up from current file
34
- let currentDir = dirname(fileURLToPath(import.meta.url));
35
- let attempts = 0;
36
- const maxAttempts = 10;
37
-
38
- while (attempts < maxAttempts) {
39
- try {
40
- const pkgPath = resolve(currentDir, "package.json");
41
- const pkgContent = readFileSync(pkgPath, "utf-8");
42
- const pkg = JSON.parse(pkgContent);
43
-
44
- // Check if this is the root by looking for workspaces
45
- if (pkg.workspaces) {
46
- return pkg.version;
47
- }
48
- } catch {
49
- // File doesn't exist or couldn't be read, continue up
50
- }
51
-
52
- const parentDir = dirname(currentDir);
53
- if (parentDir === currentDir) {
54
- // Reached filesystem root
55
- break;
56
- }
57
- currentDir = parentDir;
58
- attempts++;
59
- }
60
- } catch (error) {
61
- console.warn("Could not read root package.json, using package version as build version:", error);
62
- }
63
-
64
- return "";
65
- }
66
-
67
- export function hpccBundleNames(pkg: any) {
68
- const external: string[] = [];
69
- const globals: { [id: string]: string } = {};
70
- for (const dep in pkg.dependencies ?? {}) {
71
- external.push(dep);
72
- globals[dep] = dep;
73
- }
74
- for (const dep in pkg.peerDependencies ?? {}) {
75
- external.push(dep);
76
- globals[dep] = dep;
77
- }
78
- return { alias: (pkg.name !== "@hpcc-js/common" && pkg.dependencies?.["@hpcc-js/common"]) ? alias : {}, external, globals };
79
- }
80
-
81
- const commonCoverageConfig = {
82
- reporter: ["text", "json", "html"],
83
- exclude: [
84
- ...configDefaults.coverage.exclude || [],
85
- "**/*.spec.ts",
86
- "**/*.test.ts",
87
- "**/tests/**",
88
- "**/dist/**",
89
- "**/lib-*/**",
90
- "**/types/**",
91
- ]
92
- };
93
-
94
- export interface ViteHpccConfigOptions {
95
- /**
96
- * Additional external items
97
- */
98
- external?: string[];
99
- /**
100
- * Additional plugins to include in the configuration
101
- */
102
- plugins?: any[];
103
- /**
104
- * Whether to include font-awesome static copy (used by @hpcc-js/common)
105
- */
106
- includeFontAwesome?: boolean;
107
- /**
108
- * Custom entry point (defaults to "src/index.ts")
109
- */
110
- entry?: string;
111
- /**
112
- * Additional vite config options to merge
113
- */
114
- configOverrides?: Partial<ViteUserConfig>;
115
- }
116
-
117
- export const nodeConfig = defineConfig({
118
- test: {
119
- name: "node",
120
-
121
- exclude: [
122
- ...configDefaults.exclude,
123
- "**/*.browser.spec.{ts,js}",
124
- "**/node_modules/**",
125
- "**/.nx/**",
126
- "**/apps/**",
127
- "**/components/**",
128
- "**/demos/**",
129
- ],
130
- environment: "node",
131
- setupFiles: [],
132
- coverage: {
133
- provider: "v8",
134
- ...commonCoverageConfig
135
- }
136
- }
137
- });
138
-
139
- export const browserConfig = defineConfig({
140
- test: {
141
- exclude: [
142
- ...configDefaults.exclude,
143
- "@hpcc-js/dgrid-shim",
144
- "**/*.node.spec.{ts,js}",
145
- "**/node_modules/**",
146
- "**/.nx/**",
147
- "**/apps/**",
148
- "**/components/**",
149
- "**/demos/**",
150
- "**/src/**",
151
- ],
152
- browser: {
153
- enabled: true,
154
- provider: "playwright",
155
- instances: [{
156
- name: "chromium",
157
- browser: "chromium",
158
- headless: true,
159
- //@ts-expect-error
160
- launch: {
161
- args: ["--disable-web-security"],
162
- }
163
- }],
164
- screenshotFailures: false,
165
- },
166
- setupFiles: [],
167
- coverage: {
168
- provider: "istanbul",
169
- ...commonCoverageConfig
170
- }
171
- }
172
- });
173
-
174
- export function createHpccViteConfig(pkg: any, options: ViteHpccConfigOptions = {}): ViteUserConfig {
175
- const {
176
- external: additionalExternal = [],
177
- plugins: additionalPlugins = [],
178
- includeFontAwesome = false,
179
- entry = "src/index.ts",
180
- configOverrides = {},
181
- } = options;
182
-
183
- const { alias, external, globals } = hpccBundleNames(pkg);
184
- const allExternals = [...external, ...additionalExternal];
185
-
186
- // Get build version from root package.json
187
- const buildVersion = getRootPackageVersion() || pkg.version;
188
-
189
- const allPlugins = [
190
- packageVersionPlugin({ pkg, buildVersion }),
191
- cssInjectedByJsPlugin({
192
- topExecutionPriority: false
193
- }),
194
- ...additionalPlugins
195
- ];
196
-
197
- if (includeFontAwesome) {
198
- allPlugins.push(
199
- viteStaticCopy({
200
- targets: [
201
- {
202
- src: "../../node_modules/font-awesome/fonts",
203
- dest: "../font-awesome"
204
- }, {
205
- src: "../../node_modules/font-awesome/css",
206
- dest: "../font-awesome",
207
- }
208
- ]
209
- })
210
- );
211
- }
212
-
213
- const defaultLibConfig = {
214
- entry,
215
- name: pkg.name,
216
- fileName: "index",
217
- };
218
-
219
- const config: ViteUserConfig = {
220
- build: {
221
- lib: {
222
- ...defaultLibConfig,
223
- ...(configOverrides.build?.lib || {})
224
- },
225
- rollupOptions: {
226
- external: allExternals,
227
- output: {
228
- globals,
229
- },
230
- ...(configOverrides.build?.rollupOptions || {})
231
- },
232
- // Preserve class names and function names in minified output
233
- minify: "terser",
234
- terserOptions: {
235
- keep_classnames: true,
236
- mangle: {
237
- keep_classnames: true,
238
- }
239
- },
240
- sourcemap: true,
241
- ...(configOverrides.build ? Object.fromEntries(Object.entries(configOverrides.build).filter(([key]) => key !== "lib" && key !== "rollupOptions")) : {})
242
- },
243
- resolve: {
244
- alias,
245
- ...(configOverrides.resolve || {})
246
- },
247
- esbuild: {
248
- keepNames: true,
249
- ...(configOverrides.esbuild || {})
250
- },
251
- plugins: allPlugins,
252
- test: {
253
- projects: [nodeConfig, browserConfig],
254
- ...(configOverrides.test || {})
255
- },
256
- ...Object.fromEntries(Object.entries(configOverrides).filter(([key]) => !["build", "resolve", "esbuild", "plugins"].includes(key)))
257
- };
258
-
259
- return defineConfig(config);
1
+ import { configDefaults, defineConfig, ViteUserConfig } from "vitest/config";
2
+ import { playwright } from "@vitest/browser-playwright";
3
+ import cssInjectedByJsPlugin from "vite-plugin-css-injected-by-js";
4
+ import { viteStaticCopy } from "vite-plugin-static-copy";
5
+ import { packageVersionPlugin } from "./package-version-plugin.ts";
6
+ import { readFileSync } from "fs";
7
+ import { resolve, dirname } from "path";
8
+ import { fileURLToPath } from "url";
9
+
10
+ const alias = {
11
+ "d3-array": "@hpcc-js/common",
12
+ "d3-brush": "@hpcc-js/common",
13
+ "d3-collection": "@hpcc-js/common",
14
+ "d3-color": "@hpcc-js/common",
15
+ "d3-dispatch": "@hpcc-js/common",
16
+ "d3-drag": "@hpcc-js/common",
17
+ "d3-dsv": "@hpcc-js/common",
18
+ "d3-ease": "@hpcc-js/common",
19
+ "d3-format": "@hpcc-js/common",
20
+ "d3-interpolate": "@hpcc-js/common",
21
+ "d3-scale": "@hpcc-js/common",
22
+ "d3-selection": "@hpcc-js/common",
23
+ "d3-time-format": "@hpcc-js/common",
24
+ "d3-transition": "@hpcc-js/common",
25
+ "d3-zoom": "@hpcc-js/common"
26
+ };
27
+
28
+ /**
29
+ * Find and read the root package.json (monorepo root)
30
+ * Walks up the directory tree looking for a package.json with "workspaces"
31
+ */
32
+ function getRootPackageVersion(): string {
33
+ try {
34
+ // Try to find root package.json by walking up from current file
35
+ let currentDir = dirname(fileURLToPath(import.meta.url));
36
+ let attempts = 0;
37
+ const maxAttempts = 10;
38
+
39
+ while (attempts < maxAttempts) {
40
+ try {
41
+ const pkgPath = resolve(currentDir, "package.json");
42
+ const pkgContent = readFileSync(pkgPath, "utf-8");
43
+ const pkg = JSON.parse(pkgContent);
44
+
45
+ // Check if this is the root by looking for workspaces
46
+ if (pkg.workspaces) {
47
+ return pkg.version;
48
+ }
49
+ } catch {
50
+ // File doesn't exist or couldn't be read, continue up
51
+ }
52
+
53
+ const parentDir = dirname(currentDir);
54
+ if (parentDir === currentDir) {
55
+ // Reached filesystem root
56
+ break;
57
+ }
58
+ currentDir = parentDir;
59
+ attempts++;
60
+ }
61
+ } catch (error) {
62
+ console.warn("Could not read root package.json, using package version as build version:", error);
63
+ }
64
+
65
+ return "";
66
+ }
67
+
68
+ export function hpccBundleNames(pkg: any) {
69
+ const external: string[] = [];
70
+ const globals: { [id: string]: string } = {};
71
+ for (const dep in pkg.dependencies ?? {}) {
72
+ external.push(dep);
73
+ globals[dep] = dep;
74
+ }
75
+ for (const dep in pkg.peerDependencies ?? {}) {
76
+ external.push(dep);
77
+ globals[dep] = dep;
78
+ }
79
+ return { alias: (pkg.name !== "@hpcc-js/common" && pkg.dependencies?.["@hpcc-js/common"]) ? alias : {}, external, globals };
80
+ }
81
+
82
+ const commonCoverageConfig = {
83
+ reporter: ["text", "json", "html"],
84
+ exclude: [
85
+ ...configDefaults.coverage.exclude || [],
86
+ "**/*.spec.ts",
87
+ "**/*.test.ts",
88
+ "**/tests/**",
89
+ "**/dist/**",
90
+ "**/lib-*/**",
91
+ "**/types/**",
92
+ ]
93
+ };
94
+
95
+ export interface ViteHpccConfigOptions {
96
+ /**
97
+ * Additional external items
98
+ */
99
+ external?: string[];
100
+ /**
101
+ * Additional plugins to include in the configuration
102
+ */
103
+ plugins?: any[];
104
+ /**
105
+ * Whether to include font-awesome static copy (used by @hpcc-js/common)
106
+ */
107
+ includeFontAwesome?: boolean;
108
+ /**
109
+ * Custom entry point (defaults to "src/index.ts")
110
+ */
111
+ entry?: string;
112
+ /**
113
+ * Additional vite config options to merge
114
+ */
115
+ configOverrides?: Partial<ViteUserConfig>;
116
+ }
117
+
118
+ export const nodeConfig = defineConfig({
119
+ test: {
120
+ name: "node",
121
+
122
+ exclude: [
123
+ ...configDefaults.exclude,
124
+ "**/*.browser.spec.{ts,js}",
125
+ "**/node_modules/**",
126
+ "**/.nx/**",
127
+ "**/apps/**",
128
+ "**/components/**",
129
+ "**/demos/**",
130
+ ],
131
+ environment: "node",
132
+ setupFiles: [],
133
+ coverage: {
134
+ provider: "v8",
135
+ ...commonCoverageConfig
136
+ }
137
+ }
138
+ });
139
+
140
+ export const browserConfig = defineConfig({
141
+ test: {
142
+ exclude: [
143
+ ...configDefaults.exclude,
144
+ "@hpcc-js/dgrid-shim",
145
+ "**/*.node.spec.{ts,js}",
146
+ "**/node_modules/**",
147
+ "**/.nx/**",
148
+ "**/apps/**",
149
+ "**/components/**",
150
+ "**/demos/**",
151
+ "**/src/**",
152
+ ],
153
+ browser: {
154
+ enabled: true,
155
+ provider: playwright({
156
+ launchOptions: {
157
+ args: ["--disable-web-security"],
158
+ }
159
+ }),
160
+ instances: [{
161
+ name: "chromium",
162
+ browser: "chromium",
163
+ headless: true,
164
+ }],
165
+ screenshotFailures: false,
166
+ },
167
+ setupFiles: [],
168
+ coverage: {
169
+ provider: "istanbul",
170
+ ...commonCoverageConfig
171
+ }
172
+ }
173
+ });
174
+
175
+ export function createHpccViteConfig(pkg: any, options: ViteHpccConfigOptions = {}): ViteUserConfig {
176
+ const {
177
+ external: additionalExternal = [],
178
+ plugins: additionalPlugins = [],
179
+ includeFontAwesome = false,
180
+ entry = "src/index.ts",
181
+ configOverrides = {},
182
+ } = options;
183
+
184
+ const { alias, external, globals } = hpccBundleNames(pkg);
185
+ const allExternals = [...external, ...additionalExternal];
186
+
187
+ // Get build version from root package.json
188
+ const buildVersion = getRootPackageVersion() || pkg.version;
189
+
190
+ const allPlugins = [
191
+ packageVersionPlugin({ pkg, buildVersion }),
192
+ cssInjectedByJsPlugin({
193
+ topExecutionPriority: false
194
+ }),
195
+ ...additionalPlugins
196
+ ];
197
+
198
+ if (includeFontAwesome) {
199
+ allPlugins.push(
200
+ viteStaticCopy({
201
+ targets: [
202
+ {
203
+ src: "../../node_modules/font-awesome/fonts",
204
+ dest: "../font-awesome"
205
+ }, {
206
+ src: "../../node_modules/font-awesome/css",
207
+ dest: "../font-awesome",
208
+ }
209
+ ]
210
+ })
211
+ );
212
+ }
213
+
214
+ const defaultLibConfig = {
215
+ entry,
216
+ name: pkg.name,
217
+ fileName: "index",
218
+ };
219
+
220
+ const config: ViteUserConfig = {
221
+ build: {
222
+ lib: {
223
+ ...defaultLibConfig,
224
+ ...(configOverrides.build?.lib || {})
225
+ },
226
+ rollupOptions: {
227
+ external: allExternals,
228
+ output: {
229
+ globals,
230
+ },
231
+ ...(configOverrides.build?.rollupOptions || {})
232
+ },
233
+ // Preserve class names and function names in minified output
234
+ minify: "terser",
235
+ terserOptions: {
236
+ keep_classnames: true,
237
+ mangle: {
238
+ keep_classnames: true,
239
+ }
240
+ },
241
+ sourcemap: true,
242
+ ...(configOverrides.build ? Object.fromEntries(Object.entries(configOverrides.build).filter(([key]) => key !== "lib" && key !== "rollupOptions")) : {})
243
+ },
244
+ resolve: {
245
+ alias,
246
+ ...(configOverrides.resolve || {})
247
+ },
248
+ esbuild: {
249
+ keepNames: true,
250
+ ...(configOverrides.esbuild || {})
251
+ },
252
+ plugins: allPlugins,
253
+ test: {
254
+ projects: [nodeConfig, browserConfig],
255
+ ...(configOverrides.test || {})
256
+ },
257
+ ...Object.fromEntries(Object.entries(configOverrides).filter(([key]) => !["build", "resolve", "esbuild", "plugins"].includes(key)))
258
+ };
259
+
260
+ return defineConfig(config);
260
261
  }
@@ -29,5 +29,5 @@ export interface ViteHpccConfigOptions {
29
29
  configOverrides?: Partial<ViteUserConfig>;
30
30
  }
31
31
  export declare const nodeConfig: ViteUserConfig;
32
- export declare const browserConfig: ViteUserConfig & Promise<ViteUserConfig> & (import("vitest/config").UserConfigFnObject & import("vitest/config").UserConfigExport);
32
+ export declare const browserConfig: ViteUserConfig;
33
33
  export declare function createHpccViteConfig(pkg: any, options?: ViteHpccConfigOptions): ViteUserConfig;