@trackunit/iris-app-sdk-vite 1.12.2 → 1.12.3-alpha-52afdafac12.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": "@trackunit/iris-app-sdk-vite",
3
- "version": "1.12.2",
3
+ "version": "1.12.3-alpha-52afdafac12.0",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "repository": "https://github.com/Trackunit/manager",
6
6
  "executors": "./executors.json",
@@ -11,8 +11,8 @@
11
11
  "rxjs": "7.8.2",
12
12
  "win-ca": "^3.5.1",
13
13
  "node-forge": "^1.4.3",
14
- "@trackunit/iris-app-build-utilities": "^3.0.41",
15
- "@trackunit/iris-app-api": "^2.13.29",
14
+ "@trackunit/iris-app-build-utilities": "3.0.42-alpha-52afdafac12.0",
15
+ "@trackunit/iris-app-api": "2.13.30-alpha-52afdafac12.0",
16
16
  "tslib": "^2.6.2",
17
17
  "typescript": "6.0.2",
18
18
  "vite": "8.3.4",
@@ -20,11 +20,11 @@
20
20
  "@module-federation/vite": "1.23.4",
21
21
  "vite-plugin-checker": "^0.14.5",
22
22
  "vite-plugin-css-injected-by-js": "5.0.2",
23
- "rollup-plugin-visualizer": "5.12.0",
23
+ "rollup-plugin-visualizer": "7.1.3",
24
24
  "@tailwindcss/postcss": "^4.1.18",
25
25
  "@vitejs/plugin-react-swc": "^4.3.3",
26
26
  "@nx/devkit": "23.3.0",
27
- "@trackunit/iris-app": "^2.16.39",
27
+ "@trackunit/iris-app": "2.16.40-alpha-52afdafac12.0",
28
28
  "cross-keychain": "^1.1.0",
29
29
  "jwt-decode": "^3.1.2"
30
30
  },
@@ -14,6 +14,7 @@ const devServerTiming_1 = require("./devServerTiming");
14
14
  const duplicateTrackunitPackagesPlugin_1 = require("./duplicateTrackunitPackagesPlugin/duplicateTrackunitPackagesPlugin");
15
15
  const extensionLoaderCache_1 = require("./extensionLoaderCache");
16
16
  const loadCssInjectedByJsPlugin_1 = require("./loadCssInjectedByJsPlugin");
17
+ const loadVisualizerPlugin_1 = require("./loadVisualizerPlugin/loadVisualizerPlugin");
17
18
  const manifestCache_1 = require("./manifestCache");
18
19
  const manifestLoader_1 = require("./manifestLoader");
19
20
  const resolveSdkVersion_1 = require("./resolveSdkVersion");
@@ -221,8 +222,7 @@ async function getTrackunitIrisAppVitePlugins(options) {
221
222
  // Compute output directory: dist/apps/{app-name}
222
223
  const appName = path.basename(resolvedAppDir);
223
224
  const statsPath = path.join(workspaceRoot, "dist", "apps", appName, "stats.html");
224
- // Dynamic ESM import for optional dependency
225
- const { visualizer } = await Promise.resolve().then(() => tslib_1.__importStar(require("rollup-plugin-visualizer")));
225
+ const visualizer = await (0, loadVisualizerPlugin_1.loadVisualizerPlugin)(workspaceRoot);
226
226
  bundleAnalyzerPlugin = visualizer({
227
227
  filename: statsPath,
228
228
  template: "treemap",
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultSearchRoots = exports.isRecord = void 0;
4
+ exports.resolveEsmOnlyPackageEntry = resolveEsmOnlyPackageEntry;
5
+ exports.importEsmEntry = importEsmEntry;
6
+ const tslib_1 = require("tslib");
7
+ /**
8
+ * Indirect ESM import for packages that only publish an `import` export condition.
9
+ *
10
+ * This package is built as CommonJS, and Nx's CJS executor hooks do the same,
11
+ * so a dynamic `import("pkg")` is emitted as `require("pkg")`. For a package
12
+ * without a `require` condition that fails with `ERR_PACKAGE_PATH_NOT_EXPORTED`.
13
+ *
14
+ * The package's ESM entry is therefore resolved from its manifest and loaded via
15
+ * an indirect `new Function("return import(...)")` so Node really does an ESM
16
+ * import. Delete this module once the executors run as native ESM.
17
+ */
18
+ const fs = tslib_1.__importStar(require("node:fs"));
19
+ const path = tslib_1.__importStar(require("node:path"));
20
+ const node_url_1 = require("node:url");
21
+ const PREFERRED_CONDITIONS = ["import", "module"];
22
+ // "require" would resolve to a CJS build that the ESM import below cannot use.
23
+ const IGNORED_CONDITIONS = new Set(["require", "types"]);
24
+ /** Narrow an unknown value, such as a parsed manifest or module namespace, to an object. */
25
+ const isRecord = (value) => typeof value === "object" && value !== null;
26
+ exports.isRecord = isRecord;
27
+ /**
28
+ * Find the installed package directory by walking node_modules upwards.
29
+ *
30
+ * require.resolve() cannot be used here: the package only publishes an
31
+ * "import" export condition, so CJS resolution fails with
32
+ * ERR_PACKAGE_PATH_NOT_EXPORTED.
33
+ */
34
+ function findPackageDirFrom(packageName, startDir) {
35
+ let dir = path.resolve(startDir);
36
+ for (;;) {
37
+ const candidate = path.join(dir, "node_modules", packageName);
38
+ if (fs.existsSync(path.join(candidate, "package.json"))) {
39
+ return candidate;
40
+ }
41
+ const parent = path.dirname(dir);
42
+ if (parent === dir) {
43
+ return undefined;
44
+ }
45
+ dir = parent;
46
+ }
47
+ }
48
+ /**
49
+ * Search this module's own tree before the consumer's workspace root.
50
+ *
51
+ * Under isolated node_modules layouts (pnpm, Yarn's `nodeLinker: pnpm`) the
52
+ * package is installed beside the SDK and never appears at the consumer root,
53
+ * so a root-only walk would fail for published consumers.
54
+ */
55
+ const defaultSearchRoots = (workspaceRoot) => [__dirname, workspaceRoot];
56
+ exports.defaultSearchRoots = defaultSearchRoots;
57
+ function findPackageDir(packageName, searchRoots) {
58
+ for (const root of searchRoots) {
59
+ const found = findPackageDirFrom(packageName, root);
60
+ if (found) {
61
+ return found;
62
+ }
63
+ }
64
+ return undefined;
65
+ }
66
+ /** Walk nested export conditions, preferring the ESM ones. */
67
+ function pickEsmEntry(target) {
68
+ if (typeof target === "string") {
69
+ return target;
70
+ }
71
+ if (!(0, exports.isRecord)(target)) {
72
+ return undefined;
73
+ }
74
+ const remaining = Object.keys(target).filter(condition => !PREFERRED_CONDITIONS.includes(condition) && !IGNORED_CONDITIONS.has(condition));
75
+ for (const condition of [...PREFERRED_CONDITIONS, ...remaining]) {
76
+ const entry = pickEsmEntry(target[condition]);
77
+ if (entry) {
78
+ return entry;
79
+ }
80
+ }
81
+ return undefined;
82
+ }
83
+ /**
84
+ * Resolve the absolute ESM entry point of an installed package.
85
+ *
86
+ * The entry is read from the package manifest so that a renamed or relocated
87
+ * published entry point does not break the build.
88
+ */
89
+ function resolveEsmOnlyPackageEntry(packageName, workspaceRoot, searchRoots = (0, exports.defaultSearchRoots)(workspaceRoot)) {
90
+ const packageDir = findPackageDir(packageName, searchRoots);
91
+ if (!packageDir) {
92
+ throw new Error(`${packageName} not found in node_modules under ${searchRoots.join(", ")}. Run yarn install.`);
93
+ }
94
+ const manifest = JSON.parse(fs.readFileSync(path.join(packageDir, "package.json"), "utf-8"));
95
+ if (!(0, exports.isRecord)(manifest)) {
96
+ throw new Error(`${packageName} has an unreadable package.json in ${packageDir}.`);
97
+ }
98
+ // "exports" is either a bare entry or a subpath map holding the root entry.
99
+ const exportsField = manifest.exports;
100
+ const rootExport = (0, exports.isRecord)(exportsField) ? exportsField["."] : exportsField;
101
+ const entry = pickEsmEntry(rootExport) ?? pickEsmEntry(manifest.module) ?? pickEsmEntry(manifest.main) ?? "dist/index.js";
102
+ const entryPath = path.join(packageDir, entry);
103
+ if (!fs.existsSync(entryPath)) {
104
+ throw new Error(`${packageName} entry point not found at ${entryPath}. Run yarn install.`);
105
+ }
106
+ return entryPath;
107
+ }
108
+ /** Import the module namespace from an entry resolved by {@link resolveEsmOnlyPackageEntry}. */
109
+ async function importEsmEntry(entryPath) {
110
+ const importEsm = new Function("specifier", "return import(specifier)");
111
+ const mod = await importEsm((0, node_url_1.pathToFileURL)(entryPath).href);
112
+ return mod;
113
+ }
114
+ //# sourceMappingURL=importEsmOnlyPackage.js.map
@@ -1,139 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultSearchRoots = void 0;
4
- exports.resolveCssInjectedByJsPluginEntry = resolveCssInjectedByJsPluginEntry;
3
+ exports.resolveCssInjectedByJsPluginEntry = void 0;
5
4
  exports.loadCssInjectedByJsPlugin = loadCssInjectedByJsPlugin;
6
- const tslib_1 = require("tslib");
7
- /**
8
- * Indirect loader for `vite-plugin-css-injected-by-js` (ESM-only since v5).
9
- *
10
- * ## Why this file exists
11
- *
12
- * 1. Iris remotes must inject CSS into the JS bundle. The host iframe's CSP
13
- * blocks external stylesheets, so a separate `.css` file leaves the app
14
- * unstyled. Vite 8/Rolldown stopped emitting CSS the way Rollup did, so we
15
- * need this plugin (v5+) to inline it.
16
- * 2. The plugin only publishes an `import` export condition. A plain
17
- * `import … from "vite-plugin-css-injected-by-js"` (or a static `require`)
18
- * fails under Nx's CJS executor hooks, which rewrite dynamic `import()` into
19
- * `require()` and hit `ERR_PACKAGE_PATH_NOT_EXPORTED`.
20
- *
21
- * This module therefore resolves the package's ESM entry from its manifest and
22
- * loads it via an indirect `new Function("return import(...)")` so Node really
23
- * does an ESM import.
24
- *
25
- * ## When to delete this file
26
- *
27
- * Replace the call site in `getTrackunitIrisAppVitePlugins.ts` with a normal
28
- * `import cssInjectedByJsPlugin from "vite-plugin-css-injected-by-js"` and
29
- * delete this module once **all** of the following are true:
30
- *
31
- * - Nx executors for this package run as native ESM (no CJS rewrite of
32
- * `import()`), **or** the plugin ships a CJS/`require` export again; and
33
- * - A plain static import of the plugin works inside
34
- * `yarn nx build <any-iris-app>` (Iris apps still load with styles).
35
- *
36
- * Until then, do not "simplify" this back to a static import — that is the
37
- * regression that left Iris apps blank after the Vite 8 upgrade.
38
- */
39
- const fs = tslib_1.__importStar(require("node:fs"));
40
- const path = tslib_1.__importStar(require("node:path"));
41
- const node_url_1 = require("node:url");
5
+ const importEsmOnlyPackage_1 = require("./importEsmOnlyPackage/importEsmOnlyPackage");
42
6
  const PACKAGE_NAME = "vite-plugin-css-injected-by-js";
43
- const PREFERRED_CONDITIONS = ["import", "module"];
44
- // "require" would resolve to a CJS build that the ESM import below cannot use.
45
- const IGNORED_CONDITIONS = new Set(["require", "types"]);
46
- const isRecord = (value) => typeof value === "object" && value !== null;
47
- /**
48
- * Find the installed package directory by walking node_modules upwards.
49
- *
50
- * require.resolve() cannot be used here: the package only publishes an
51
- * "import" export condition, so CJS resolution fails with
52
- * ERR_PACKAGE_PATH_NOT_EXPORTED.
53
- */
54
- function findPackageDirFrom(startDir) {
55
- let dir = path.resolve(startDir);
56
- for (;;) {
57
- const candidate = path.join(dir, "node_modules", PACKAGE_NAME);
58
- if (fs.existsSync(path.join(candidate, "package.json"))) {
59
- return candidate;
60
- }
61
- const parent = path.dirname(dir);
62
- if (parent === dir) {
63
- return undefined;
64
- }
65
- dir = parent;
66
- }
67
- }
68
- /**
69
- * Search this module's own tree before the consumer's workspace root.
70
- *
71
- * Under isolated node_modules layouts (pnpm, Yarn's `nodeLinker: pnpm`) this
72
- * package is installed beside the SDK and never appears at the consumer root,
73
- * so a root-only walk would fail for published consumers.
74
- */
75
- const defaultSearchRoots = (workspaceRoot) => [__dirname, workspaceRoot];
76
- exports.defaultSearchRoots = defaultSearchRoots;
77
- function findPackageDir(searchRoots) {
78
- for (const root of searchRoots) {
79
- const found = findPackageDirFrom(root);
80
- if (found) {
81
- return found;
82
- }
83
- }
84
- return undefined;
85
- }
86
- /** Walk nested export conditions, preferring the ESM ones. */
87
- function pickEsmEntry(target) {
88
- if (typeof target === "string") {
89
- return target;
90
- }
91
- if (!isRecord(target)) {
92
- return undefined;
93
- }
94
- const remaining = Object.keys(target).filter(condition => !PREFERRED_CONDITIONS.includes(condition) && !IGNORED_CONDITIONS.has(condition));
95
- for (const condition of [...PREFERRED_CONDITIONS, ...remaining]) {
96
- const entry = pickEsmEntry(target[condition]);
97
- if (entry) {
98
- return entry;
99
- }
100
- }
101
- return undefined;
102
- }
103
- /**
104
- * Resolve the absolute ESM entry point of the installed package.
105
- *
106
- * The entry is read from the package manifest so that a renamed or relocated
107
- * published entry point does not break the build.
108
- */
109
- function resolveCssInjectedByJsPluginEntry(workspaceRoot, searchRoots = (0, exports.defaultSearchRoots)(workspaceRoot)) {
110
- const packageDir = findPackageDir(searchRoots);
111
- if (!packageDir) {
112
- throw new Error(`${PACKAGE_NAME} not found in node_modules under ${searchRoots.join(", ")}. Run yarn install.`);
113
- }
114
- const manifest = JSON.parse(fs.readFileSync(path.join(packageDir, "package.json"), "utf-8"));
115
- if (!isRecord(manifest)) {
116
- throw new Error(`${PACKAGE_NAME} has an unreadable package.json in ${packageDir}.`);
117
- }
118
- // "exports" is either a bare entry or a subpath map holding the root entry.
119
- const exportsField = manifest.exports;
120
- const rootExport = isRecord(exportsField) ? exportsField["."] : exportsField;
121
- const entry = pickEsmEntry(rootExport) ?? pickEsmEntry(manifest.module) ?? pickEsmEntry(manifest.main) ?? "dist/index.js";
122
- const entryPath = path.join(packageDir, entry);
123
- if (!fs.existsSync(entryPath)) {
124
- throw new Error(`${PACKAGE_NAME} entry point not found at ${entryPath}. Run yarn install.`);
125
- }
126
- return entryPath;
127
- }
7
+ /** Resolve the absolute ESM entry point of the installed plugin. */
8
+ const resolveCssInjectedByJsPluginEntry = (workspaceRoot) => (0, importEsmOnlyPackage_1.resolveEsmOnlyPackageEntry)(PACKAGE_NAME, workspaceRoot);
9
+ exports.resolveCssInjectedByJsPluginEntry = resolveCssInjectedByJsPluginEntry;
128
10
  /**
129
11
  * Load the CSS-injection plugin factory. See the file-level comment for why
130
12
  * this cannot be a static import, and what has to change before it can be.
131
13
  */
132
14
  async function loadCssInjectedByJsPlugin(workspaceRoot) {
133
- const entryPath = resolveCssInjectedByJsPluginEntry(workspaceRoot);
134
- const importEsm = new Function("specifier", "return import(specifier)");
135
- const mod = await importEsm((0, node_url_1.pathToFileURL)(entryPath).href);
136
- const factory = isRecord(mod) ? mod.default : undefined;
15
+ const entryPath = (0, exports.resolveCssInjectedByJsPluginEntry)(workspaceRoot);
16
+ const mod = await (0, importEsmOnlyPackage_1.importEsmEntry)(entryPath);
17
+ const factory = (0, importEsmOnlyPackage_1.isRecord)(mod) ? mod.default : undefined;
137
18
  if (typeof factory !== "function") {
138
19
  throw new Error(`${PACKAGE_NAME} at ${entryPath} did not export a plugin factory as its default export.`);
139
20
  }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveVisualizerPluginEntry = void 0;
4
+ exports.loadVisualizerPlugin = loadVisualizerPlugin;
5
+ const importEsmOnlyPackage_1 = require("../importEsmOnlyPackage/importEsmOnlyPackage");
6
+ const PACKAGE_NAME = "rollup-plugin-visualizer";
7
+ /** Resolve the absolute ESM entry point of the installed plugin. */
8
+ const resolveVisualizerPluginEntry = (workspaceRoot) => (0, importEsmOnlyPackage_1.resolveEsmOnlyPackageEntry)(PACKAGE_NAME, workspaceRoot);
9
+ exports.resolveVisualizerPluginEntry = resolveVisualizerPluginEntry;
10
+ /** Load the bundle analyzer plugin factory. */
11
+ async function loadVisualizerPlugin(workspaceRoot) {
12
+ const entryPath = (0, exports.resolveVisualizerPluginEntry)(workspaceRoot);
13
+ const mod = await (0, importEsmOnlyPackage_1.importEsmEntry)(entryPath);
14
+ const factory = (0, importEsmOnlyPackage_1.isRecord)(mod) ? mod.visualizer : undefined;
15
+ if (typeof factory !== "function") {
16
+ throw new Error(`${PACKAGE_NAME} at ${entryPath} did not export a visualizer plugin factory.`);
17
+ }
18
+ return options => factory(options);
19
+ }
20
+ //# sourceMappingURL=loadVisualizerPlugin.js.map
@@ -23,7 +23,7 @@ const readPackageName = (packageDir) => {
23
23
  const isIrisAppPackageDir = (packageDir) => fs.existsSync(path.join(packageDir, "package.json")) && readPackageName(packageDir) === PACKAGE_NAME;
24
24
  /**
25
25
  * Walks `node_modules` upwards from `fromDir` looking for `@trackunit/iris-app`.
26
- * Mirrors the layout-tolerant walk in `loadCssInjectedByJsPlugin` so both classic
26
+ * Mirrors the layout-tolerant walk in `importEsmOnlyPackage` so both classic
27
27
  * hoisted installs and Yarn/pnpm isolated layouts resolve correctly.
28
28
  */
29
29
  const findIrisAppInNodeModules = (fromDir) => {