@astryxdesign/build 0.6.4 → 0.6.5-canary.00f1ed9
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 +26 -10
- package/package.json +2 -1
- package/src/vite.build.test.ts +51 -2
- package/src/vite.test.ts +40 -0
- package/src/vite.ts +27 -10
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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.
|
|
3
|
+
"version": "0.6.5-canary.00f1ed9",
|
|
4
4
|
"description": "Build plugins for Astryx source builds — babel, PostCSS, and Vite integrations",
|
|
5
5
|
"author": "Meta Open Source",
|
|
6
6
|
"license": "MIT",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"lightningcss": "^1.32.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
+
"enhanced-resolve": "^5.21.6",
|
|
53
54
|
"esbuild": "^0.28.1"
|
|
54
55
|
},
|
|
55
56
|
"peerDependenciesMeta": {
|
package/src/vite.build.test.ts
CHANGED
|
@@ -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 {
|
|
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;
|
|
@@ -195,7 +205,9 @@ function itSplitsCorrectly(get: () => Built) {
|
|
|
195
205
|
// output means running the same pass, or the build quietly loses the prefixes
|
|
196
206
|
// the original had.
|
|
197
207
|
it('keeps the vendor prefixing StyleX applies', () => {
|
|
198
|
-
|
|
208
|
+
// `-webkit-box-orient` is authored in source, so only a prefix the pass
|
|
209
|
+
// adds shows that it ran.
|
|
210
|
+
expect(get().css).toContain('-webkit-user-select');
|
|
199
211
|
});
|
|
200
212
|
|
|
201
213
|
it('links the stylesheet from the page', () => {
|
|
@@ -205,6 +217,43 @@ function itSplitsCorrectly(get: () => Built) {
|
|
|
205
217
|
});
|
|
206
218
|
}
|
|
207
219
|
|
|
220
|
+
describe('a production build resolves generated locale modules', () => {
|
|
221
|
+
it('loads a generated string map through the standard Astryx Vite aliases', async () => {
|
|
222
|
+
const root = realpathSync(
|
|
223
|
+
mkdtempSync(path.join(tmpdir(), 'astryx-locale-import-')),
|
|
224
|
+
);
|
|
225
|
+
const packageDir = path.join(root, 'node_modules/@astryxdesign');
|
|
226
|
+
const outDir = path.join(root, 'dist');
|
|
227
|
+
mkdirSync(packageDir, {recursive: true});
|
|
228
|
+
symlinkSync(CORE_PACKAGE, path.join(packageDir, 'core'), 'dir');
|
|
229
|
+
writeFileSync(
|
|
230
|
+
path.join(root, 'index.html'),
|
|
231
|
+
'<script type="module" src="/main.ts"></script>',
|
|
232
|
+
);
|
|
233
|
+
writeFileSync(
|
|
234
|
+
path.join(root, 'main.ts'),
|
|
235
|
+
`import frFR from '@astryxdesign/core/locales/fr-FR.generated.js';\ndocument.body.textContent = frFR['@astryx.pagination.next'];\n`,
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
try {
|
|
239
|
+
await build({
|
|
240
|
+
root,
|
|
241
|
+
logLevel: 'error',
|
|
242
|
+
build: {outDir, emptyOutDir: true, minify: false},
|
|
243
|
+
plugins: [...astryxStylex({rootDir: root})],
|
|
244
|
+
});
|
|
245
|
+
const assets = path.join(outDir, 'assets');
|
|
246
|
+
const jsName = readdirSync(assets).find(file => file.endsWith('.js'));
|
|
247
|
+
expect(jsName).toBeTruthy();
|
|
248
|
+
expect(readFileSync(path.join(assets, jsName!), 'utf8')).toContain(
|
|
249
|
+
'Aller à la page suivante',
|
|
250
|
+
);
|
|
251
|
+
} finally {
|
|
252
|
+
rmSync(root, {recursive: true, force: true});
|
|
253
|
+
}
|
|
254
|
+
}, 180_000);
|
|
255
|
+
});
|
|
256
|
+
|
|
208
257
|
describe('a production build separates Astryx and product styles by layer', () => {
|
|
209
258
|
describe('when the app imports a stylesheet of its own', () => {
|
|
210
259
|
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
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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,
|