@astryxdesign/build 0.6.4 → 0.6.5-canary.c3016f8

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
@@ -86,18 +86,34 @@ function astryxStylex(options = {}) {
86
86
  }
87
87
  } catch {
88
88
  }
89
+ const corePackageDir = path.resolve(
90
+ rootDir,
91
+ "node_modules/@astryxdesign/core"
92
+ );
93
+ const coreSourceDir = path.join(corePackageDir, "src");
89
94
  return {
90
95
  resolve: {
91
- alias: {
92
- "@astryxdesign/core/theme/tokens.stylex": path.resolve(
93
- rootDir,
94
- "node_modules/@astryxdesign/core/src/theme/tokens.stylex.ts"
95
- ),
96
- "@astryxdesign/core": path.resolve(
97
- rootDir,
98
- "node_modules/@astryxdesign/core/src"
99
- )
100
- }
96
+ alias: [
97
+ {
98
+ find: /^@astryxdesign\/core\/locales\/(.+)\.generated\.js$/,
99
+ replacement: path.join(
100
+ coreSourceDir,
101
+ "i18n/generated-locales/$1.generated.ts"
102
+ )
103
+ },
104
+ {
105
+ find: /^@astryxdesign\/core\/locales\/(.+)\.json$/,
106
+ replacement: path.join(corePackageDir, "locales/$1.json")
107
+ },
108
+ {
109
+ find: "@astryxdesign/core/theme/tokens.stylex",
110
+ replacement: path.join(coreSourceDir, "theme/tokens.stylex.ts")
111
+ },
112
+ {
113
+ find: "@astryxdesign/core",
114
+ replacement: coreSourceDir
115
+ }
116
+ ]
101
117
  },
102
118
  optimizeDeps: {
103
119
  exclude: xdsPackages
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/build",
3
- "version": "0.6.4",
3
+ "version": "0.6.5-canary.c3016f8",
4
4
  "description": "Build plugins for Astryx source builds — babel, PostCSS, and Vite integrations",
5
5
  "author": "Meta Open Source",
6
6
  "license": "MIT",
@@ -33,7 +33,16 @@
33
33
  import {describe, it, expect, beforeAll, afterAll} from 'vitest';
34
34
  import {build} from 'vite';
35
35
  import react from '@vitejs/plugin-react';
36
- import {mkdtempSync, readdirSync, readFileSync, rmSync} from 'node:fs';
36
+ import {
37
+ mkdirSync,
38
+ mkdtempSync,
39
+ readdirSync,
40
+ readFileSync,
41
+ realpathSync,
42
+ rmSync,
43
+ symlinkSync,
44
+ writeFileSync,
45
+ } from 'node:fs';
37
46
  import {tmpdir} from 'node:os';
38
47
  import * as path from 'node:path';
39
48
  import {fileURLToPath} from 'node:url';
@@ -43,6 +52,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
43
52
  const REPO_ROOT = path.resolve(__dirname, '../../..');
44
53
  const FIXTURES = path.resolve(__dirname, '../__fixtures__');
45
54
  const CORE_SRC = path.join(REPO_ROOT, 'packages/core/src');
55
+ const CORE_PACKAGE = path.join(REPO_ROOT, 'packages/core');
46
56
 
47
57
  /** The class prefixes @astryxdesign/build/babel assigns per origin. */
48
58
  const LIBRARY_CLASS = /\.astryx[a-z0-9]{5,}/g;
@@ -205,6 +215,43 @@ function itSplitsCorrectly(get: () => Built) {
205
215
  });
206
216
  }
207
217
 
218
+ describe('a production build resolves generated locale modules', () => {
219
+ it('loads a generated string map through the standard Astryx Vite aliases', async () => {
220
+ const root = realpathSync(
221
+ mkdtempSync(path.join(tmpdir(), 'astryx-locale-import-')),
222
+ );
223
+ const packageDir = path.join(root, 'node_modules/@astryxdesign');
224
+ const outDir = path.join(root, 'dist');
225
+ mkdirSync(packageDir, {recursive: true});
226
+ symlinkSync(CORE_PACKAGE, path.join(packageDir, 'core'), 'dir');
227
+ writeFileSync(
228
+ path.join(root, 'index.html'),
229
+ '<script type="module" src="/main.ts"></script>',
230
+ );
231
+ writeFileSync(
232
+ path.join(root, 'main.ts'),
233
+ `import frFR from '@astryxdesign/core/locales/fr-FR.generated.js';\ndocument.body.textContent = frFR['@astryx.pagination.next'];\n`,
234
+ );
235
+
236
+ try {
237
+ await build({
238
+ root,
239
+ logLevel: 'error',
240
+ build: {outDir, emptyOutDir: true, minify: false},
241
+ plugins: [...astryxStylex({rootDir: root})],
242
+ });
243
+ const assets = path.join(outDir, 'assets');
244
+ const jsName = readdirSync(assets).find(file => file.endsWith('.js'));
245
+ expect(jsName).toBeTruthy();
246
+ expect(readFileSync(path.join(assets, jsName!), 'utf8')).toContain(
247
+ 'Aller à la page suivante',
248
+ );
249
+ } finally {
250
+ rmSync(root, {recursive: true, force: true});
251
+ }
252
+ }, 180_000);
253
+ });
254
+
208
255
  describe('a production build separates Astryx and product styles by layer', () => {
209
256
  describe('when the app imports a stylesheet of its own', () => {
210
257
  let built: Built;
package/src/vite.test.ts CHANGED
@@ -16,6 +16,26 @@ import {astryxStylex} from './vite';
16
16
 
17
17
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
18
18
 
19
+ function getInjectedConfig(rootDir: string): any {
20
+ const plugins = astryxStylex({rootDir});
21
+ const configPlugin = plugins.find(p => p.name === 'astryx-config');
22
+ expect(configPlugin, 'astryx-config plugin should exist').toBeTruthy();
23
+ const config = (configPlugin as any).config;
24
+ return typeof config === 'function' ? config() : config.handler();
25
+ }
26
+
27
+ function applyAlias(aliases: any[], id: string): string {
28
+ for (const alias of aliases) {
29
+ if (
30
+ (typeof alias.find === 'string' && id.startsWith(alias.find)) ||
31
+ (alias.find instanceof RegExp && alias.find.test(id))
32
+ ) {
33
+ return id.replace(alias.find, alias.replacement);
34
+ }
35
+ }
36
+ return id;
37
+ }
38
+
19
39
  /** Pull the injected `@layer ...;` order statement out of the plugin set. */
20
40
  function getLayerOrder(plugins: ReturnType<typeof astryxStylex>): string {
21
41
  const layerPlugin = plugins.find(p => p.name === 'astryx-css-layer-order');
@@ -99,6 +119,26 @@ describe('astryxStylex build-time layer split', () => {
99
119
  });
100
120
  });
101
121
 
122
+ describe('astryxStylex locale aliases', () => {
123
+ it('routes generated and rich locale imports to their real package files', () => {
124
+ const rootDir = path.join(tmpdir(), 'astryx-vite-alias');
125
+ const aliases = getInjectedConfig(rootDir).resolve.alias;
126
+ const corePackage = path.join(rootDir, 'node_modules/@astryxdesign/core');
127
+
128
+ expect(
129
+ applyAlias(aliases, '@astryxdesign/core/locales/fr-FR.generated.js'),
130
+ ).toBe(
131
+ path.join(corePackage, 'src/i18n/generated-locales/fr-FR.generated.ts'),
132
+ );
133
+ expect(applyAlias(aliases, '@astryxdesign/core/locales/fr-FR.json')).toBe(
134
+ path.join(corePackage, 'locales/fr-FR.json'),
135
+ );
136
+ expect(applyAlias(aliases, '@astryxdesign/core/Button')).toBe(
137
+ path.join(corePackage, 'src/Button'),
138
+ );
139
+ });
140
+ });
141
+
102
142
  describe('astryxStylex optimizeDeps package discovery', () => {
103
143
  let rootDir: string;
104
144
 
package/src/vite.ts CHANGED
@@ -204,18 +204,35 @@ export function astryxStylex(
204
204
  // Fallback to just @astryxdesign/core if discovery fails
205
205
  }
206
206
 
207
+ const corePackageDir = path.resolve(
208
+ rootDir,
209
+ 'node_modules/@astryxdesign/core',
210
+ );
211
+ const coreSourceDir = path.join(corePackageDir, 'src');
212
+
207
213
  return {
208
214
  resolve: {
209
- alias: {
210
- '@astryxdesign/core/theme/tokens.stylex': path.resolve(
211
- rootDir,
212
- 'node_modules/@astryxdesign/core/src/theme/tokens.stylex.ts',
213
- ),
214
- '@astryxdesign/core': path.resolve(
215
- rootDir,
216
- 'node_modules/@astryxdesign/core/src',
217
- ),
218
- },
215
+ alias: [
216
+ {
217
+ find: /^@astryxdesign\/core\/locales\/(.+)\.generated\.js$/,
218
+ replacement: path.join(
219
+ coreSourceDir,
220
+ 'i18n/generated-locales/$1.generated.ts',
221
+ ),
222
+ },
223
+ {
224
+ find: /^@astryxdesign\/core\/locales\/(.+)\.json$/,
225
+ replacement: path.join(corePackageDir, 'locales/$1.json'),
226
+ },
227
+ {
228
+ find: '@astryxdesign/core/theme/tokens.stylex',
229
+ replacement: path.join(coreSourceDir, 'theme/tokens.stylex.ts'),
230
+ },
231
+ {
232
+ find: '@astryxdesign/core',
233
+ replacement: coreSourceDir,
234
+ },
235
+ ],
219
236
  },
220
237
  optimizeDeps: {
221
238
  exclude: xdsPackages,