@astryxdesign/build 0.3.0 → 0.4.0-canary.3112e99

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/vite.mjs CHANGED
@@ -1,14 +1,9 @@
1
1
  // Built from src/vite.ts — do not edit directly
2
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
- }) : x)(function(x) {
5
- if (typeof require !== "undefined") return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
2
 
9
3
  // src/vite.ts
10
4
  import stylexBabelPlugin from "@stylexjs/babel-plugin";
11
5
  import stylex from "@stylexjs/unplugin";
6
+ import fs from "node:fs";
12
7
  import path from "node:path";
13
8
  import { fileURLToPath } from "node:url";
14
9
  var __dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -82,7 +77,6 @@ function astryxStylex(options = {}) {
82
77
  config() {
83
78
  let xdsPackages = ["@astryxdesign/core"];
84
79
  try {
85
- const fs = __require("node:fs");
86
80
  const xdsDir = path.resolve(rootDir, "node_modules/@astryxdesign");
87
81
  if (fs.existsSync(xdsDir)) {
88
82
  xdsPackages = fs.readdirSync(xdsDir).filter((name) => !name.startsWith(".")).map((name) => `@astryxdesign/${name}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/build",
3
- "version": "0.3.0",
3
+ "version": "0.4.0-canary.3112e99",
4
4
  "description": "Build plugins for XDS source builds — babel, PostCSS, and Vite integrations",
5
5
  "author": "Meta Open Source",
6
6
  "license": "MIT",
package/src/vite.test.ts CHANGED
@@ -7,13 +7,22 @@
7
7
  * theme layer name is fixed at `astryx-theme`.
8
8
  */
9
9
 
10
- import {describe, it, expect} from 'vitest';
10
+ import {describe, it, expect, beforeAll, afterAll} from 'vitest';
11
+ import {mkdtempSync, mkdirSync, rmSync} from 'node:fs';
12
+ import {tmpdir} from 'node:os';
13
+ import path from 'node:path';
14
+ import {fileURLToPath, pathToFileURL} from 'node:url';
11
15
  import {astryxStylex} from './vite';
12
16
 
17
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
18
+
13
19
  /** Pull the injected `@layer ...;` order statement out of the plugin set. */
14
20
  function getLayerOrder(plugins: ReturnType<typeof astryxStylex>): string {
15
21
  const layerPlugin = plugins.find(p => p.name === 'astryx-css-layer-order');
16
- expect(layerPlugin, 'astryx-css-layer-order plugin should exist').toBeTruthy();
22
+ expect(
23
+ layerPlugin,
24
+ 'astryx-css-layer-order plugin should exist',
25
+ ).toBeTruthy();
17
26
  const transform = (layerPlugin as any).transformIndexHtml;
18
27
  const tags =
19
28
  typeof transform === 'function' ? transform() : transform.handler();
@@ -43,3 +52,98 @@ describe('astryxStylex layer order (legacy API)', () => {
43
52
  expect(order).toBe('@layer reset, astryx-base, astryx-theme, product;');
44
53
  });
45
54
  });
55
+
56
+ describe('astryxStylex optimizeDeps package discovery', () => {
57
+ let rootDir: string;
58
+
59
+ beforeAll(() => {
60
+ rootDir = mkdtempSync(path.join(tmpdir(), 'astryx-vite-'));
61
+ for (const pkg of ['core', 'icons', 'charts']) {
62
+ mkdirSync(path.join(rootDir, 'node_modules', '@astryxdesign', pkg), {
63
+ recursive: true,
64
+ });
65
+ }
66
+ mkdirSync(path.join(rootDir, 'node_modules', '@astryxdesign', '.cache'), {
67
+ recursive: true,
68
+ });
69
+ });
70
+
71
+ afterAll(() => {
72
+ rmSync(rootDir, {recursive: true, force: true});
73
+ });
74
+
75
+ function getExclude(rootDirOption: string): string[] {
76
+ const plugins = astryxStylex({rootDir: rootDirOption});
77
+ const configPlugin = plugins.find(p => p.name === 'astryx-config');
78
+ expect(configPlugin, 'astryx-config plugin should exist').toBeTruthy();
79
+ const config = (configPlugin as any).config;
80
+ const result = typeof config === 'function' ? config() : config.handler();
81
+ return result.optimizeDeps.exclude;
82
+ }
83
+
84
+ it('excludes every installed @astryxdesign/* package, not just core', () => {
85
+ expect(getExclude(rootDir).sort()).toEqual([
86
+ '@astryxdesign/charts',
87
+ '@astryxdesign/core',
88
+ '@astryxdesign/icons',
89
+ ]);
90
+ });
91
+
92
+ it('falls back to @astryxdesign/core when no packages are installed', () => {
93
+ expect(getExclude(path.join(rootDir, 'does-not-exist'))).toEqual([
94
+ '@astryxdesign/core',
95
+ ]);
96
+ });
97
+
98
+ // Vitest's module transform provides a working `require` even for dynamic
99
+ // file-URL imports, so an in-process test cannot catch CJS-isms that only
100
+ // break in the shipped ESM bundle. This test compiles vite.ts exactly like
101
+ // build.mjs does, then runs the discovery in a child `node` process under
102
+ // real ESM semantics (where `require` is undefined).
103
+ it('still discovers packages in the compiled ESM bundle (dist contract)', async () => {
104
+ const {buildSync} = await import('esbuild');
105
+ const {execFileSync} = await import('node:child_process');
106
+ // Emit next to src/ so the bundle's externals (vite, @stylexjs/*)
107
+ // resolve against this package's node_modules; dist/ is gitignored.
108
+ const outfile = path.join(__dirname, '..', 'dist', 'vite.test-esm.mjs');
109
+ try {
110
+ buildSync({
111
+ entryPoints: [path.join(__dirname, 'vite.ts')],
112
+ bundle: true,
113
+ platform: 'node',
114
+ format: 'esm',
115
+ outfile,
116
+ // SYNC: keep aligned with the external list in build.mjs
117
+ external: [
118
+ 'vite',
119
+ '@stylexjs/babel-plugin',
120
+ '@stylexjs/unplugin',
121
+ 'path',
122
+ 'url',
123
+ 'node:fs',
124
+ 'node:path',
125
+ 'node:url',
126
+ ],
127
+ });
128
+ const script = [
129
+ `const {astryxStylex} = await import(${JSON.stringify(pathToFileURL(outfile).href)});`,
130
+ `const plugin = astryxStylex({rootDir: ${JSON.stringify(rootDir)}})`,
131
+ ` .find(p => p.name === 'astryx-config');`,
132
+ `console.log(JSON.stringify(plugin.config().optimizeDeps.exclude));`,
133
+ ].join('\n');
134
+ const stdout = execFileSync(
135
+ process.execPath,
136
+ ['--input-type=module', '-e', script],
137
+ {encoding: 'utf8'},
138
+ );
139
+ const exclude: string[] = JSON.parse(stdout.trim());
140
+ expect(exclude.sort()).toEqual([
141
+ '@astryxdesign/charts',
142
+ '@astryxdesign/core',
143
+ '@astryxdesign/icons',
144
+ ]);
145
+ } finally {
146
+ rmSync(outfile, {force: true});
147
+ }
148
+ });
149
+ });
package/src/vite.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  import type {Plugin, UserConfig} from 'vite';
4
4
  import stylexBabelPlugin from '@stylexjs/babel-plugin';
5
5
  import stylex from '@stylexjs/unplugin';
6
+ import fs from 'node:fs';
6
7
  import path from 'node:path';
7
8
  import {fileURLToPath} from 'node:url';
8
9
 
@@ -189,13 +190,12 @@ export function astryxStylex(
189
190
  // strips stylex.create/defineVars calls and causes runtime errors.
190
191
  let xdsPackages: string[] = ['@astryxdesign/core'];
191
192
  try {
192
- const fs = require('node:fs');
193
193
  const xdsDir = path.resolve(rootDir, 'node_modules/@astryxdesign');
194
194
  if (fs.existsSync(xdsDir)) {
195
195
  xdsPackages = fs
196
196
  .readdirSync(xdsDir)
197
- .filter((name: string) => !name.startsWith('.'))
198
- .map((name: string) => `@astryxdesign/${name}`);
197
+ .filter(name => !name.startsWith('.'))
198
+ .map(name => `@astryxdesign/${name}`);
199
199
  }
200
200
  } catch {
201
201
  // Fallback to just @astryxdesign/core if discovery fails