@imtf/profile-scripts 2.0.0-beta.1 → 2.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imtf/profile-scripts",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0",
4
4
  "description": "Default scripts to bundle & transpile imtf front-end plugins",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -20,13 +20,12 @@
20
20
  "private": false,
21
21
  "dependencies": {
22
22
  "@originjs/vite-plugin-federation": "^1.4.1",
23
- "@vitejs/plugin-react": "^5.1.4",
24
- "esbuild": "^0.27.0",
23
+ "@vitejs/plugin-react": "^6.0.4",
24
+ "esbuild": "^0.28.1",
25
25
  "minimist": "^1.2.8",
26
- "serve-handler": "^6.1.6",
27
- "vite": "^7.3.1",
28
- "vite-plugin-css-injected-by-js": "^4.0.1",
29
- "vite-tsconfig-paths": "^6.0.1"
26
+ "serve-handler": "^6.1.7",
27
+ "vite": "^8.1.5",
28
+ "vite-plugin-css-injected-by-js": "^5.0.2"
30
29
  },
31
30
  "devDependencies": {
32
31
  "@types/minimist": "^1.2.5"
@@ -8,9 +8,8 @@ import react from "@vitejs/plugin-react";
8
8
  import { transform } from "esbuild";
9
9
  import minimist from "minimist";
10
10
  import handler from "serve-handler";
11
- import { build as viteBuild } from "vite";
11
+ import { build as viteBuild, esmExternalRequirePlugin } from "vite";
12
12
  import cssInjectedByJsPlugin from "vite-plugin-css-injected-by-js";
13
- import tsconfigPaths from "vite-tsconfig-paths";
14
13
 
15
14
  import resolveEntryPoint from "./utils/resolveEntryPoint.mjs";
16
15
  import notifierPlugin from "./vitePlugins/viteNotifierPlugin.mjs";
@@ -21,7 +20,9 @@ const {
21
20
  entryPoint,
22
21
  externalGlobal,
23
22
  federation: enableFederation,
24
- } = minimist(process.argv.slice(2));
23
+ } = /** @type {{ watch?: boolean; entryPoint?: string; externalGlobal?: string | string[]; federation?: boolean }} */ (
24
+ minimist(process.argv.slice(2))
25
+ );
25
26
 
26
27
  const consumerRoot = process.cwd();
27
28
  const outDir = "build";
@@ -32,7 +33,7 @@ const entryAbs = resolveEntryPoint(entryPoint);
32
33
  const jsxPreTransformPlugin = {
33
34
  name: "jsx-pre-transform",
34
35
  enforce: "pre",
35
- async transform(code, id) {
36
+ async transform(/** @type {string} */ code, /** @type {string} */ id) {
36
37
  if (id.endsWith(".js") && id.includes(path.resolve(consumerRoot, "src"))) {
37
38
  const result = await transform(code, {
38
39
  loader: "jsx",
@@ -54,7 +55,7 @@ const jsxPreTransformPlugin = {
54
55
  const packageJsonResolver = {
55
56
  name: "package-json-resolver",
56
57
  enforce: "pre",
57
- resolveId(source) {
58
+ resolveId(/** @type {string} */ source) {
58
59
  if (!source.endsWith("/package.json")) return null;
59
60
 
60
61
  const pkgName = source.replace(/\/package\.json$/, "");
@@ -83,8 +84,8 @@ const externalGlobals = externalGlobal
83
84
  const [key, value] = curr.split("=");
84
85
  acc[key] = value;
85
86
  return acc;
86
- }, {})
87
- : {};
87
+ }, /** @type {Record<string, string>} */ ({}))
88
+ : /** @type {Record<string, string>} */ ({});
88
89
 
89
90
  // Dynamically resolve optional federation.config.(js|mjs) from consumer root
90
91
  const resolveFederationConfig = async () => {
@@ -95,7 +96,10 @@ const resolveFederationConfig = async () => {
95
96
  for (const file of candidates) {
96
97
  const fullPath = path.resolve(consumerRoot, file);
97
98
  if (fs.existsSync(fullPath)) {
98
- const mod = await import(pathToFileURL(fullPath).href);
99
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
100
+ const mod = /** @type {Record<string, unknown>} */ (
101
+ await import(pathToFileURL(fullPath).href)
102
+ );
99
103
  return mod.default ?? mod;
100
104
  }
101
105
  }
@@ -120,9 +124,6 @@ const vitePlugins = [
120
124
  include: /\.(js|jsx|ts|tsx)$/,
121
125
  }),
122
126
 
123
- // Resolve tsconfig path aliases
124
- tsconfigPaths(),
125
-
126
127
  // Inject CSS into the bundle for library consumers without needing separate CSS files
127
128
  cssInjectedByJsPlugin(),
128
129
 
@@ -137,6 +138,17 @@ const vitePlugins = [
137
138
  if (enableFederation) {
138
139
  const federationConfig = await resolveFederationConfig();
139
140
  vitePlugins.push(federation(federationConfig));
141
+ // Vite 8 (rolldown) disables codeSplitting for iife format, making manualChunks invalid.
142
+ // Since this is a consumer-only federation setup, manualChunks is not needed.
143
+ vitePlugins.push({
144
+ name: "remove-manual-chunks-for-iife",
145
+ enforce: "post",
146
+ outputOptions(opts) {
147
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
148
+ delete opts.manualChunks;
149
+ return opts;
150
+ },
151
+ });
140
152
  }
141
153
 
142
154
  /**
@@ -155,17 +167,25 @@ const viteConfig = {
155
167
  chunkSizeWarningLimit: 3000,
156
168
  rollupOptions: {
157
169
  input: entryAbs,
158
- external: [
159
- "react",
160
- "react-dom",
161
- "react-router-dom",
162
- "IMTFPlugins",
163
- ...Object.keys(externalGlobals),
170
+ // Fixes Vite 8+ (rolldown) leaving a literal require("react") for nested CJS deps
171
+ // in 'iife' output (rolldown/rolldown#8349). Don't also list these in a top-level
172
+ // 'external' option - that silently disables this plugin's require() rewrite for
173
+ // the duplicated entries.
174
+ plugins: [
175
+ esmExternalRequirePlugin({
176
+ external: [
177
+ "react",
178
+ "react-dom",
179
+ "react-router-dom",
180
+ "IMTFPlugins",
181
+ ...Object.keys(externalGlobals),
182
+ ],
183
+ }),
164
184
  ],
165
185
  output: {
166
186
  entryFileNames: "index.js",
167
187
  format: "iife",
168
- inlineDynamicImports: false,
188
+ // inlineDynamicImports: false,
169
189
  globals: {
170
190
  react: "React",
171
191
  "react-dom": "ReactDOM",
@@ -178,6 +198,9 @@ const viteConfig = {
178
198
  minify: watch ? false : process.env.IMTF_MINIFY_WEBAPP !== "false",
179
199
  watch: watch ? {} : null,
180
200
  },
201
+ define: {
202
+ "import.meta": "{}",
203
+ },
181
204
  };
182
205
 
183
206
  // Run Vite build in either watch or build mode
@@ -185,6 +208,7 @@ if (watch) {
185
208
  await viteBuild(viteConfig);
186
209
 
187
210
  http
211
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-return
188
212
  .createServer((...params) => handler(...params, { public: outDir }))
189
213
  .listen(3010, () => {
190
214
  // eslint-disable-next-line no-console
@@ -1,3 +1,5 @@
1
+ /* eslint-disable no-console */
2
+
1
3
  /**
2
4
  * Logs Vite build and rebuild status with rebuild count.
3
5
  * Distinguishes initial build vs subsequent rebuilds in watch mode.
@@ -1,10 +1,15 @@
1
+ import fs from "node:fs";
2
+ import path from "path";
3
+
4
+ import { transform } from "@svgr/core";
5
+
1
6
  /**
2
7
  * Vite plugin to transform SVG imports based on project conventions.
3
8
  *
4
9
  * - SVGs outside `src/` or inside `src/assets/` are converted to base64 data URLs
5
10
  * - SVGs inside `src/` are transformed into React components using SVGR
6
11
  *
7
- * @param {Object} [options] - SVGR configuration options
12
+ * @param {Record<string, unknown>} [options] - SVGR configuration options
8
13
  * @returns {import('vite').Plugin}
9
14
  */
10
15
  const viteSvgPlugin = (options = {}) => {
@@ -31,7 +36,7 @@ const viteSvgPlugin = (options = {}) => {
31
36
  const dataurl = `data:image/svg+xml;base64,${Buffer.from(svg).toString("base64")}`;
32
37
  return {
33
38
  code: `export default ${JSON.stringify(dataurl)};`,
34
- map: null
39
+ map: null,
35
40
  };
36
41
  }
37
42
 
@@ -40,17 +45,17 @@ const viteSvgPlugin = (options = {}) => {
40
45
  svg,
41
46
  {
42
47
  plugins: ["@svgr/plugin-svgo", "@svgr/plugin-jsx"],
43
- ...options
48
+ ...options,
44
49
  },
45
- { filePath: svgPath }
50
+ { filePath: svgPath },
46
51
  );
47
52
 
48
53
  return {
49
54
  code: contents,
50
- map: null
55
+ map: null,
51
56
  };
52
- }
57
+ },
53
58
  };
54
- }
59
+ };
55
60
 
56
61
  export default viteSvgPlugin;