@astryxdesign/build 0.7.11-canary.ec945c9 → 0.7.11
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/README.md +1 -3
- package/dist/vite.mjs +1 -9
- package/package.json +1 -1
- package/src/babel.js +3 -15
- package/src/index.js +2 -14
- package/src/next.js +0 -9
- package/src/vite.ts +3 -16
- package/src/swizzle-marker-loader.js +0 -25
- package/src/swizzle-marker.d.ts +0 -19
- package/src/swizzle-marker.js +0 -68
package/README.md
CHANGED
|
@@ -156,7 +156,7 @@ module.exports = {
|
|
|
156
156
|
|
|
157
157
|
### 3. next.config.mjs
|
|
158
158
|
|
|
159
|
-
Or `withAstryx()` from `@astryxdesign/build/next`, which sets both of these for you.
|
|
159
|
+
Or `withAstryx()` from `@astryxdesign/build/next`, which sets both of these for you.
|
|
160
160
|
Either way the work happens in the `webpack` hook, so the build has to run with
|
|
161
161
|
`--webpack` — see the note at the top of this section.
|
|
162
162
|
|
|
@@ -253,8 +253,6 @@ Library patterns (configurable):
|
|
|
253
253
|
- `packages/themes/`
|
|
254
254
|
- `node_modules/@astryxdesign/`
|
|
255
255
|
|
|
256
|
-
A swizzled copy is library code too. The Babel, PostCSS, and Vite integrations compile every module under a folder that holds an `astryx-swizzle.json` marker with the library prefix into `@layer astryx-base`, so a theme's component overrides reach the copy as they reach the package component. `astryx swizzle` does not write the marker yet: add it to the swizzle output folder, naming the package the copy came from and its version, such as `{"packages": {"@astryxdesign/core": "0.7.10"}}`. The build reads only whether the file is there. Under webpack, use `withAstryx()` with a marked copy: it makes each app module depend on the marker paths above it, so a dev session or a cached build recompiles a copy when its marker appears or disappears. In another setup that caches transforms, restart the dev server and delete that cache after adding or removing a marker. Turbopack builds do not read the marker yet.
|
|
257
|
-
|
|
258
256
|
### PostCSS plugin (`@astryxdesign/build/postcss`)
|
|
259
257
|
|
|
260
258
|
Compiles StyleX from both library and product source files in two separate passes with different prefixes. Wraps the results in named `@layer` blocks:
|
package/dist/vite.mjs
CHANGED
|
@@ -29,13 +29,6 @@ function undefinedGeneratedVariables(css, prefixes, others = []) {
|
|
|
29
29
|
|
|
30
30
|
// src/vite.ts
|
|
31
31
|
var __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
32
|
-
var markerReader;
|
|
33
|
-
function isSwizzledSource(filePath, memo) {
|
|
34
|
-
markerReader ??= createRequire(import.meta.url)(
|
|
35
|
-
path.resolve(__dirname, "../src/swizzle-marker.js")
|
|
36
|
-
);
|
|
37
|
-
return markerReader.isSwizzledSource(filePath, memo);
|
|
38
|
-
}
|
|
39
32
|
var LIBRARY_PATTERN = "node_modules/@astryxdesign/";
|
|
40
33
|
var STYLEX_CSS_PATH = "/virtual:stylex.css";
|
|
41
34
|
var LIGHTNINGCSS_TARGETS = {
|
|
@@ -207,9 +200,8 @@ function renderSplitLayers(rulesById, options) {
|
|
|
207
200
|
const libraryRules = [];
|
|
208
201
|
const productRules = [];
|
|
209
202
|
const collectedConstants = [];
|
|
210
|
-
const markerMemo = /* @__PURE__ */ new Map();
|
|
211
203
|
for (const [filePath, rules] of rulesById.entries()) {
|
|
212
|
-
const own = filePath.includes(options.libraryPattern)
|
|
204
|
+
const own = filePath.includes(options.libraryPattern) ? libraryRules : productRules;
|
|
213
205
|
for (const rule of rules) {
|
|
214
206
|
if (isConstantRule(rule)) {
|
|
215
207
|
collectedConstants.push(rule);
|
package/package.json
CHANGED
package/src/babel.js
CHANGED
|
@@ -11,9 +11,6 @@
|
|
|
11
11
|
* Library files get 'astryx' prefix (.astryx78zum5), product files get 'x' (.x78zum5).
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
const path = require('node:path');
|
|
15
|
-
const {isSwizzledSource} = require('./swizzle-marker');
|
|
16
|
-
|
|
17
14
|
const LIBRARY_PATTERNS = [
|
|
18
15
|
'packages/core/',
|
|
19
16
|
'packages/themes/',
|
|
@@ -50,17 +47,8 @@ module.exports = function astryxBabelPlugin(api, options) {
|
|
|
50
47
|
const libraryPlugin = stylexPlugin(api, libraryOpts);
|
|
51
48
|
const productPlugin = stylexPlugin(api, productOpts);
|
|
52
49
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
function getPluginAndOpts(state) {
|
|
56
|
-
let isLibrary = libraryFiles.get(state.file);
|
|
57
|
-
if (isLibrary === undefined) {
|
|
58
|
-
const filename = state.filename || '';
|
|
59
|
-
isLibrary =
|
|
60
|
-
libraryPatterns.some(p => filename.includes(p)) ||
|
|
61
|
-
(filename !== '' && isSwizzledSource(path.resolve(filename)));
|
|
62
|
-
if (state.file != null) libraryFiles.set(state.file, isLibrary);
|
|
63
|
-
}
|
|
50
|
+
function getPluginAndOpts(filename) {
|
|
51
|
+
const isLibrary = libraryPatterns.some(p => filename.includes(p));
|
|
64
52
|
return isLibrary
|
|
65
53
|
? {plugin: libraryPlugin, opts: libraryOpts}
|
|
66
54
|
: {plugin: productPlugin, opts: productOpts};
|
|
@@ -68,7 +56,7 @@ module.exports = function astryxBabelPlugin(api, options) {
|
|
|
68
56
|
|
|
69
57
|
// Helper: call a visitor function with overridden state.opts
|
|
70
58
|
function callVisitor(visitor, key, path, state) {
|
|
71
|
-
const {plugin, opts} = getPluginAndOpts(state);
|
|
59
|
+
const {plugin, opts} = getPluginAndOpts(state.filename || '');
|
|
72
60
|
const v = plugin.visitor[key];
|
|
73
61
|
if (!v) return;
|
|
74
62
|
|
package/src/index.js
CHANGED
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
const path = require('node:path');
|
|
26
|
-
const {isSwizzledSource} = require('./swizzle-marker');
|
|
27
26
|
const fs = require('node:fs');
|
|
28
27
|
const babel = require('@babel/core');
|
|
29
28
|
const stylexBabelPlugin = require('@stylexjs/babel-plugin');
|
|
@@ -243,24 +242,11 @@ function createPlugin() {
|
|
|
243
242
|
// Partition files into library vs product, then compile
|
|
244
243
|
// each group with its own babel config (different prefix)
|
|
245
244
|
const transforms = [];
|
|
246
|
-
// A swizzled copy is Astryx source too: it compiles in the library pass.
|
|
247
|
-
const markerMemo = new Map();
|
|
248
245
|
for (const filePath of files) {
|
|
249
|
-
// Classify every file on each pass: when a marker appears or goes,
|
|
250
|
-
// `withAstryx()` rebuilds the copy with the other prefix.
|
|
251
|
-
const isLibrary =
|
|
252
|
-
libraryPatterns.some(p => filePath.includes(p)) ||
|
|
253
|
-
isSwizzledSource(filePath, markerMemo);
|
|
254
|
-
const rulesMap = isLibrary ? libraryRulesMap : productRulesMap;
|
|
255
|
-
const movedSides = (
|
|
256
|
-
isLibrary ? productRulesMap : libraryRulesMap
|
|
257
|
-
).delete(filePath);
|
|
258
|
-
|
|
259
246
|
const mtimeMs = fs.existsSync(filePath)
|
|
260
247
|
? fs.statSync(filePath).mtimeMs
|
|
261
248
|
: -Infinity;
|
|
262
249
|
if (
|
|
263
|
-
!movedSides &&
|
|
264
250
|
fileModifiedMap.has(filePath) &&
|
|
265
251
|
mtimeMs === fileModifiedMap.get(filePath)
|
|
266
252
|
) {
|
|
@@ -271,7 +257,9 @@ function createPlugin() {
|
|
|
271
257
|
const contents = fs.readFileSync(filePath, 'utf-8');
|
|
272
258
|
if (!contents.includes(STYLEX_IMPORT_SOURCE)) continue;
|
|
273
259
|
|
|
260
|
+
const isLibrary = libraryPatterns.some(p => filePath.includes(p));
|
|
274
261
|
const config = isLibrary ? libraryBabelConfig : productBabelConfig;
|
|
262
|
+
const rulesMap = isLibrary ? libraryRulesMap : productRulesMap;
|
|
275
263
|
|
|
276
264
|
transforms.push(
|
|
277
265
|
babel
|
package/src/next.js
CHANGED
|
@@ -30,7 +30,6 @@ const ASTRYX_MODULE = /[\\/]node_modules[\\/]@astryxdesign[\\/]/;
|
|
|
30
30
|
|
|
31
31
|
const escapeRegExp = text => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
32
32
|
const TURBOPACK_LOADER = require.resolve('./turbopack-loader.js');
|
|
33
|
-
const SWIZZLE_MARKER_LOADER = require.resolve('./swizzle-marker-loader.js');
|
|
34
33
|
|
|
35
34
|
/**
|
|
36
35
|
* Match a wildcard alias key such as `@astryxdesign/*` against a request. The
|
|
@@ -371,14 +370,6 @@ function withAstryx(nextConfig = {}) {
|
|
|
371
370
|
.map(name => findPackageDir(name, from))
|
|
372
371
|
.filter(dir => dir != null)
|
|
373
372
|
.map(dir => escapeRegExp(fs.realpathSync(dir) + path.sep));
|
|
374
|
-
// The app's own modules depend on the swizzle markers above them, so a
|
|
375
|
-
// cached build recompiles a copy when its marker appears or disappears.
|
|
376
|
-
config.module.rules.unshift({
|
|
377
|
-
test: /\.[cm]?[jt]sx?$/,
|
|
378
|
-
exclude: /[\\/]node_modules[\\/]/,
|
|
379
|
-
enforce: 'pre',
|
|
380
|
-
use: [{loader: SWIZZLE_MARKER_LOADER}],
|
|
381
|
-
});
|
|
382
373
|
config.module.rules.unshift({
|
|
383
374
|
test:
|
|
384
375
|
realPackageDirs.length === 0
|
package/src/vite.ts
CHANGED
|
@@ -11,15 +11,6 @@ import {createHash} from 'node:crypto';
|
|
|
11
11
|
import {undefinedGeneratedVariables} from './undefinedVariables';
|
|
12
12
|
|
|
13
13
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
14
|
-
// The CommonJS marker reader the Babel and PostCSS integrations share,
|
|
15
|
-
// loaded on first use from beside babel.js, so every integration runs one copy.
|
|
16
|
-
let markerReader: typeof import('./swizzle-marker.js') | undefined;
|
|
17
|
-
function isSwizzledSource(filePath: string, memo: Map<string, boolean>) {
|
|
18
|
-
markerReader ??= createRequire(import.meta.url)(
|
|
19
|
-
path.resolve(__dirname, 'swizzle-marker.js'),
|
|
20
|
-
) as typeof import('./swizzle-marker.js');
|
|
21
|
-
return markerReader.isSwizzledSource(filePath, memo);
|
|
22
|
-
}
|
|
23
14
|
|
|
24
15
|
const LIBRARY_PATTERN = 'node_modules/@astryxdesign/';
|
|
25
16
|
const STYLEX_CSS_PATH = '/virtual:stylex.css';
|
|
@@ -365,14 +356,10 @@ function renderSplitLayers(
|
|
|
365
356
|
// their own, so repeating them adds nothing to the output.
|
|
366
357
|
const collectedConstants: unknown[] = [];
|
|
367
358
|
|
|
368
|
-
// A swizzled copy is Astryx source too: its rules go in the library layer.
|
|
369
|
-
const markerMemo = new Map<string, boolean>();
|
|
370
359
|
for (const [filePath, rules] of rulesById.entries()) {
|
|
371
|
-
const own =
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
? libraryRules
|
|
375
|
-
: productRules;
|
|
360
|
+
const own = filePath.includes(options.libraryPattern)
|
|
361
|
+
? libraryRules
|
|
362
|
+
: productRules;
|
|
376
363
|
for (const rule of rules) {
|
|
377
364
|
if (isConstantRule(rule)) {
|
|
378
365
|
collectedConstants.push(rule);
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @astryxdesign/build: a webpack pre-loader that `withAstryx()` installs for
|
|
7
|
-
* the app's own modules. It makes each module depend on every swizzle marker
|
|
8
|
-
* path that decides how the module compiles, so webpack rebuilds the module,
|
|
9
|
-
* and its cached class names, when a marker appears or disappears. It does
|
|
10
|
-
* not change the source.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
const fs = require('node:fs');
|
|
14
|
-
const {markerPaths} = require('./swizzle-marker');
|
|
15
|
-
|
|
16
|
-
module.exports = function astryxSwizzleMarkerLoader(source, map, meta) {
|
|
17
|
-
for (const marker of markerPaths(this.resourcePath, this.rootContext)) {
|
|
18
|
-
if (fs.existsSync(marker)) {
|
|
19
|
-
this.addDependency(marker);
|
|
20
|
-
break;
|
|
21
|
-
}
|
|
22
|
-
this.addMissingDependency(marker);
|
|
23
|
-
}
|
|
24
|
-
this.callback(null, source, map, meta);
|
|
25
|
-
};
|
package/src/swizzle-marker.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
/** The marker file in a swizzle output folder. */
|
|
4
|
-
export declare const SWIZZLE_MARKER: string;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Whether a module is in a swizzled copy: a folder at or above it holds the
|
|
8
|
-
* marker. One `memo` per build pass looks each folder up once.
|
|
9
|
-
*/
|
|
10
|
-
/** The marker paths from a module's folder up to `stopDir` or the root. */
|
|
11
|
-
export declare function markerPaths(
|
|
12
|
-
filePath: string,
|
|
13
|
-
stopDir?: string,
|
|
14
|
-
): string[];
|
|
15
|
-
|
|
16
|
-
export declare function isSwizzledSource(
|
|
17
|
-
filePath: string,
|
|
18
|
-
memo?: Map<string, boolean>,
|
|
19
|
-
): boolean;
|
package/src/swizzle-marker.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @astryxdesign/build: swizzled copies. A swizzle output folder holds an
|
|
7
|
-
* `astryx-swizzle.json` marker. Every module under a folder that holds the
|
|
8
|
-
* marker is Astryx source: the library pass compiles it with
|
|
9
|
-
* the library class prefix into the library layer, below `astryx-theme`, so a
|
|
10
|
-
* theme's component overrides reach the copy as they reach the package.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
const fs = require('node:fs');
|
|
14
|
-
const path = require('node:path');
|
|
15
|
-
|
|
16
|
-
/** The marker file in a swizzle output folder. */
|
|
17
|
-
const SWIZZLE_MARKER = 'astryx-swizzle.json';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Whether a module is in a swizzled copy: a folder at or above it holds the
|
|
21
|
-
* marker. Pass one `memo` to the checks of one build pass, so each folder is
|
|
22
|
-
* looked up once; nothing is kept between passes, so a copy swizzled while a
|
|
23
|
-
* dev server runs counts from the next pass.
|
|
24
|
-
* @param {string} filePath an absolute module path
|
|
25
|
-
* @param {Map<string, boolean>} [memo] folder -> whether it or a folder
|
|
26
|
-
* above it holds the marker
|
|
27
|
-
* @returns {boolean}
|
|
28
|
-
*/
|
|
29
|
-
function isSwizzledSource(filePath, memo = new Map()) {
|
|
30
|
-
/** @type {string[]} */
|
|
31
|
-
const visited = [];
|
|
32
|
-
let dir = path.dirname(filePath);
|
|
33
|
-
let marked = false;
|
|
34
|
-
for (;;) {
|
|
35
|
-
const known = memo.get(dir);
|
|
36
|
-
if (known !== undefined) {
|
|
37
|
-
marked = known;
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
visited.push(dir);
|
|
41
|
-
if (fs.existsSync(path.join(dir, SWIZZLE_MARKER))) {
|
|
42
|
-
marked = true;
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
const parent = path.dirname(dir);
|
|
46
|
-
if (parent === dir) break;
|
|
47
|
-
dir = parent;
|
|
48
|
-
}
|
|
49
|
-
for (const folder of visited) memo.set(folder, marked);
|
|
50
|
-
return marked;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* The marker paths that decide whether a module is in a swizzled copy, from
|
|
55
|
-
* its own folder up to `stopDir` (or the file system root).
|
|
56
|
-
* @param {string} filePath an absolute module path
|
|
57
|
-
* @param {string} [stopDir] the last folder to check, such as the project root
|
|
58
|
-
* @returns {string[]}
|
|
59
|
-
*/
|
|
60
|
-
function markerPaths(filePath, stopDir) {
|
|
61
|
-
const paths = [];
|
|
62
|
-
for (let dir = path.dirname(filePath); ; dir = path.dirname(dir)) {
|
|
63
|
-
paths.push(path.join(dir, SWIZZLE_MARKER));
|
|
64
|
-
if (dir === stopDir || path.dirname(dir) === dir) return paths;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
module.exports = {SWIZZLE_MARKER, isSwizzledSource, markerPaths};
|